結果

問題 No.2165 Let's Play Nim!
ユーザー umezo
提出日時 2022-12-16 01:53:19
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 194 ms / 2,000 ms
コード長 1,832 bytes
コンパイル時間 6,519 ms
コンパイル使用メモリ 203,116 KB
最終ジャッジ日時 2025-02-09 14:13:23
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 38
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:68:11: warning: ‘tmp’ may be used uninitialized [-Wmaybe-uninitialized]
   68 |       int tmp;
      |           ^~~
main.cpp:45:11: warning: ‘tmp’ may be used uninitialized [-Wmaybe-uninitialized]
   45 |       int tmp;
      |           ^~~

ソースコード

diff #

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;
 
#include<bits/stdc++.h>
using namespace std;

set<int> G[17];
 
int main(){
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  
  int n;
  cin>>n;
  
  vector<int> A(n);
  int now=0;
  rep(i,n){
    cin>>A[i];
    rep(j,17){
      if(A[i]&(1<<j)) G[j].insert(i);
    }
    now^=A[i];
  }
  
  int ret;
  if(now==0){
    cout<<0<<endl;
    while(1){
      int i,k;
      cin>>i>>k;
      i--;
      now=A[i]^(A[i]-k);
      rep(j,17){
        if(A[i]&(1<<j)) G[j].erase(i);
      }
      A[i]-=k;
      rep(j,17){
        if(A[i]&(1<<j)) G[j].insert(i);
      }
      cin>>ret;
      if(ret==-1) return 0;
      
      int tmp;
      for(int j=16;j>=0;j--){
        if(now&(1<<j)){
          tmp=j;
          break;
        }
      }
      int c=*G[tmp].begin();
      cout<<c+1<<" "<<A[c]-(A[c]^now)<<endl;
      rep(j,17){
        if(A[c]&(1<<j)) G[j].erase(c);
      }
      A[c]^=now;
      rep(j,17){
        if(A[c]&(1<<j)) G[j].insert(c);
      }
      cin>>ret;
      if(ret==-1) return 0;
    }
  }
  else{
    cout<<1<<endl; 
    while(1){
      int tmp;
      for(int j=16;j>=0;j--){
        if(now&(1<<j)){
          tmp=j;
          break;
        }
      }
      int c=*G[tmp].begin();
      cout<<c+1<<" "<<A[c]-(A[c]^now)<<endl;
      rep(j,17){
        if(A[c]&(1<<j)) G[j].erase(c);
      }
      A[c]^=now;
      rep(j,17){
        if(A[c]&(1<<j)) G[j].insert(c);
      }
      cin>>ret;
      if(ret==-1) return 0;
      
      int i,k;
      cin>>i>>k;
      i--;
      now=A[i]^(A[i]-k);
      rep(j,17){
        if(A[i]&(1<<j)) G[j].erase(i);
      }
      A[i]-=k;
      rep(j,17){
        if(A[i]&(1<<j)) G[j].insert(i);
      }
      cin>>ret;
      if(ret==-1) return 0;
    }
  }
  
  return 0;
}
0