結果

問題 No.1816 MUL-DIV Game
ユーザー ぷら
提出日時 2022-01-21 21:27:07
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 102 ms / 2,000 ms
コード長 1,005 bytes
コンパイル時間 2,294 ms
コンパイル使用メモリ 203,520 KB
最終ジャッジ日時 2025-01-27 13:23:13
ジャッジサーバーID
(参考情報)
judge1 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main() {
    int N;
    cin >> N;
    vector<long long>A(N);
    for(int i = 0; i < N; i++) {
        cin >> A[i];
    }
    sort(A.rbegin(),A.rend());
    if(N == 1) {
        cout << A[0] << endl;
    }
    else if(N == 2) {
        cout << A[0]*A[1] << endl;
    }
    else if(N%2 == 1) {
        cout << 1 << endl;
    }
    else {
        multiset<long long>que;
        for(int i = 0; i < N; i++) {
            que.insert(A[i]);
        }
        int f = 0;
        while (que.size() >= 2) {
            if(!f) {
                long long x = *que.begin();
                que.erase(que.begin());
                long long y = *que.begin();
                que.erase(que.begin());
                que.insert(x*y);
            }
            else {
                que.erase(--que.end());
                que.erase(--que.end());
                que.insert(1);
            }
            f ^= 1;
        }
        cout << *que.begin() << endl;
    }
}
0