結果
問題 |
No.2165 Let's Play Nim!
|
ユーザー |
![]() |
提出日時 | 2022-12-16 00:30:22 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 165 ms / 2,000 ms |
コード長 | 1,853 bytes |
コンパイル時間 | 1,935 ms |
コンパイル使用メモリ | 201,428 KB |
最終ジャッジ日時 | 2025-02-09 14:11:02 |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 38 |
ソースコード
#line 1 "library/Template/template.hpp" #include <bits/stdc++.h> using namespace std; #define rep(i,a,b) for(int i=(int)(a);i<(int)(b);i++) #define ALL(v) (v).begin(),(v).end() using ll=long long int; const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; template<typename T>inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;} template<typename T>inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;} #line 2 "sol.cpp" // #include "Utility/fastio.hpp" using P=pair<int,int>; // FastIO io; int main(){ int n,tmp; cin>>n; vector<int> a(n); rep(i,0,n)cin>>a[i]; int gr=0; ll sum=0; set<int> bit[20]; auto process=[&](int k,int x){ sum-=x; gr^=a[k]; rep(j,0,20)if(a[k]>>j&1)bit[j].erase(k); a[k]-=x; gr^=a[k]; rep(j,0,20)if(a[k]>>j&1)bit[j].insert(k); }; auto out=[&](int k,int x,bool done=0)->void{ cout<<k+1<<' '<<x<<endl; cin>>tmp; if(done)assert(tmp==-1); else assert(tmp==0); }; auto in=[&]()->P{ int k,x; cin>>k>>x; k--; cin>>tmp; assert(tmp==0); return {k,x}; }; rep(i,0,n){ gr^=a[i]; sum+=a[i]; rep(j,0,20)if(a[i]>>j&1)bit[j].insert(i); } if(gr==0){ cout<<0<<endl; auto [k,x]=in(); process(k,x); } else cout<<1<<endl; for(;;){ assert(gr!=0); int sel=-1; for(int j=20;j>=0;j--){ if(gr>>j&1){ assert(bit[j].size()); sel=*bit[j].begin(); break; } } assert(sel!=-1); int x=a[sel]-(a[sel]^gr); process(sel,x); out(sel,x,sum==0); if(sum==0)break; auto [k,y]=in(); process(k,y); } return 0; }