λ³Έλ¬Έ λ°”λ‘œκ°€κΈ°
Algorithm πŸ§‘πŸ»‍πŸ’»/λ°±μ€€(BOJ)

[λ°±μ€€,c++] 14698번 - μ „μƒν–ˆλ”λ‹ˆ μŠ¬λΌμž„ μ—°κ΅¬μžμ˜€λ˜ 건에 λŒ€ν•˜μ—¬(Hard)

by dkswnkk 2021. 11. 11.

문제

 

14698번: μ „μƒν–ˆλ”λ‹ˆ μŠ¬λΌμž„ μ—°κ΅¬μžμ˜€λ˜ 건에 λŒ€ν•˜μ—¬ (Hard)

각 ν…ŒμŠ€νŠΈ μΌ€μ΄μŠ€λ§ˆλ‹€ μŠ¬λΌμž„μ„ λκΉŒμ§€ ν•©μ„±ν–ˆμ„ λ•Œ 청ꡬ될 λΉ„μš©μ˜ μ΅œμ†Ÿκ°’μ„ 1, 000, 000, 007둜 λ‚˜λˆˆ λ‚˜λ¨Έμ§€λ₯Ό 좜λ ₯ν•œλ‹€. μ „κΈ° μ—λ„ˆμ§€κ°€ μ „ν˜€ ν•„μš”ν•˜μ§€ μ•Šμ€ κ²½μš°μ—” 1 을 좜λ ₯ν•œλ‹€.

www.acmicpc.net

 

μ½”λ“œ

#include <iostream>
#include <queue>
#include <algorithm>

using namespace std;
const long long int mod = 1000000007;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int T;;
    cin >> T;
    while(T--){
        int n;
        cin >> n;
        priority_queue<long long int,vector<long long int >,greater<long long int >> pq;
        for (int i = 0; i < n; i++) {
            long long int num; cin >> num;
            pq.push(num);
        }
        long long int score = 1;
        while (pq.size() >=2) {
            long long int one = pq.top(); pq.pop();
            long long int two = pq.top(); pq.pop();
            score *= (((one % mod) * (two % mod)) % mod);
            pq.push(one * two);    
            score%=mod;
        }
    cout << score << "\n";
    }
}

λŒ“κΈ€