結果

問題 No.1816 MUL-DIV Game
ユーザー nawawannawawan
提出日時 2022-01-21 21:45:30
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,212 bytes
コンパイル時間 4,098 ms
コンパイル使用メモリ 209,540 KB
実行使用メモリ 8,960 KB
最終ジャッジ日時 2023-08-17 05:30:01
合計ジャッジ時間 7,230 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,384 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 6 ms
4,380 KB
testcase_10 AC 21 ms
4,380 KB
testcase_11 AC 19 ms
4,376 KB
testcase_12 AC 15 ms
4,380 KB
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 AC 51 ms
4,380 KB
testcase_27 RE -
testcase_28 AC 47 ms
4,380 KB
testcase_29 RE -
権限があれば一括ダウンロードができます

ソースコード

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.begin(), A.end());
    if(N == 1){
        cout << A[0] << endl;
    }
    else if(N == 2){
        cout << A[0] * A[1] << endl;
    }
    else{
        if(N % 2 == 0){
            multiset<long long> s;
            for(int i = 0; i < N; i++) s.insert(A[i]);
            int temp = N - 1;
            bool f = true;
            while(temp--){
                if(f){
                    auto ite = s.begin();
                    auto ne = next(ite);
                    long long te = *ite * *ne;
                    s.erase(s.find(*ite));
                    s.erase(s.find(*ne));
                    s.insert(te);
                }
                else{
                    auto ite = s.rbegin();
                    auto ne = ite;
                    ne++;
                    s.erase(s.find(*ite));
                    s.erase(s.find(*ne));
                    s.insert(1);
                }
                f = !f;
            }
            cout << *s.begin() << endl;
        } 
        else{
            cout << 1 << endl;
        }
    }
}
0