結果
問題 | No.3130 Twin's Add Max Min Game |
ユーザー |
|
提出日時 | 2025-04-25 22:46:14 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 56 ms / 2,000 ms |
コード長 | 2,503 bytes |
コンパイル時間 | 2,236 ms |
コンパイル使用メモリ | 205,916 KB |
実行使用メモリ | 7,848 KB |
最終ジャッジ日時 | 2025-04-25 22:46:33 |
合計ジャッジ時間 | 6,802 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 56 |
ソースコード
#include <bits/stdc++.h> using namespace std; long long jury(int N,vector<int> A,int Add,int Max,int Min){ int dep = 0; auto dfs = [&](auto dfs,vector<int> now,int ad,int ma,int mi,long long x) -> long long { dep++; int n = now.size(); if(n == 0){ dep--; return x; } long long ret = 0; for(int i=0; i<n; i++){ long long val = 1e18; long long y = now.at(i); now.erase(now.begin()+i); if(ad) val = min(val,dfs(dfs,now,ad-1,ma,mi,x+y)); if(dep == 1){ cout << "stop" << endl; } if(ma) val = min(val,dfs(dfs,now,ad,ma-1,mi,max(x,y))); if(dep == 1){ cout << "stop" << endl; } if(mi) val = min(val,dfs(dfs,now,ad,ma,mi-1,min(x,y))); if(dep == 1){ cout << "stop" << endl; } now.insert(now.begin()+i,y); ret = max(ret,val); } dep--; return ret; }; return dfs(dfs,A,Add,Max,Min,0); } random_device rnd; mt19937 mt(rnd()); int main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); int N; cin >> N; bool test = false; while(true){ vector<int> Akane(N); int Add = 0,Max = 0,Min = 0; if(test == false) for(auto &a : Akane) cin >> a; if(test) for(auto &a : Akane) a = mt()%9+1; for(int i=0; i<N; i++){ string s; int k = mt()%3; if(k == 0) s = "add"; if(k == 1) s = "max"; if(k == 2) s = "min"; if(test == false) cin >> s; if(s == "add") Add++; else if(s == "max") Max++; else Min++; } sort(Akane.rbegin(),Akane.rend()); if(Min == N){ continue; cout << 0 << endl; //かわいそう. return 0; } long long answer = Akane.at(Min); for(int i=Min+Max+1; i<N; i++) answer += Akane.at(i); if(Min) answer = min(answer,1LL*Akane.at(Min-1)); //え. if(test){ long long ju = jury(N,Akane,Add,Max,Min); if(answer != ju && test){ cout << "Wrong" << endl; cout << N << endl; for(auto a : Akane) cout << a << " "; cout << endl; cout << Add << " " << Max << " " << Min << endl; cout << answer << " " << ju << endl; return 0; } } if(test) continue; cout << answer << endl; break; } }