結果
問題 | No.1816 MUL-DIV Game |
ユーザー |
![]() |
提出日時 | 2022-01-21 21:56:22 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,021 bytes |
コンパイル時間 | 1,644 ms |
コンパイル使用メモリ | 175,064 KB |
実行使用メモリ | 8,832 KB |
最終ジャッジ日時 | 2024-11-25 23:51:26 |
合計ジャッジ時間 | 3,635 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 23 WA * 4 |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; using P = pair<ll,ll>; #define rep(i, n) for(int i = 0; i < n; i++) #define all(x) (x).begin(),(x).end() template<class T>bool chmin(T&a, const T&b){if(a>b){a=b;return 1;}return 0;} template<class T>bool chmax(T&a, const T&b){if(a<b){a=b;return 1;}return 0;} int main(){ int n; cin >> n; vector<ll> a(n); rep(i,n) cin >> a[i]; ll ans; if(n==1) ans = a[0]; else if(n==2) ans = a[0]*a[1]; else if(n%2) ans = 1; else{ set<ll> se; rep(i,n) se.insert(a[i]); while(se.size()!=1){ if(se.size()%2){ se.erase(*se.rbegin()); se.erase(*se.rbegin()); se.insert(1); }else{ ll x = *se.begin(); se.erase(x); ll y = *se.begin(); se.erase(y); se.insert(x*y); } } ans = *se.begin(); } cout << ans << endl; return 0; }