結果

問題 No.2165 Let's Play Nim!
ユーザー Nzt3Nzt3
提出日時 2022-12-18 12:43:08
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 199 ms / 2,000 ms
コード長 1,085 bytes
コンパイル時間 2,308 ms
コンパイル使用メモリ 209,868 KB
実行使用メモリ 24,252 KB
平均クエリ数 863.56
最終ジャッジ日時 2023-08-11 08:53:45
合計ジャッジ時間 17,751 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
23,592 KB
testcase_01 AC 135 ms
24,024 KB
testcase_02 AC 144 ms
23,328 KB
testcase_03 AC 90 ms
23,376 KB
testcase_04 AC 26 ms
24,048 KB
testcase_05 AC 31 ms
23,328 KB
testcase_06 AC 31 ms
23,376 KB
testcase_07 AC 30 ms
23,796 KB
testcase_08 AC 95 ms
23,916 KB
testcase_09 AC 27 ms
23,592 KB
testcase_10 AC 34 ms
23,316 KB
testcase_11 AC 139 ms
23,376 KB
testcase_12 AC 127 ms
23,832 KB
testcase_13 AC 27 ms
23,556 KB
testcase_14 AC 31 ms
23,484 KB
testcase_15 AC 28 ms
23,328 KB
testcase_16 AC 114 ms
24,252 KB
testcase_17 AC 66 ms
24,252 KB
testcase_18 AC 199 ms
23,628 KB
testcase_19 AC 28 ms
23,484 KB
testcase_20 AC 30 ms
23,928 KB
testcase_21 AC 54 ms
23,328 KB
testcase_22 AC 47 ms
23,916 KB
testcase_23 AC 44 ms
24,024 KB
testcase_24 AC 41 ms
23,928 KB
testcase_25 AC 81 ms
23,832 KB
testcase_26 AC 143 ms
23,340 KB
testcase_27 AC 49 ms
23,544 KB
testcase_28 AC 73 ms
23,412 KB
testcase_29 AC 26 ms
23,604 KB
testcase_30 AC 25 ms
23,616 KB
testcase_31 AC 25 ms
23,928 KB
testcase_32 AC 96 ms
23,568 KB
evil_2_big_1.txt AC 1,685 ms
23,664 KB
evil_2_big_2.txt AC 1,830 ms
24,024 KB
evil_2_big_3.txt AC 1,642 ms
23,556 KB
evil_big_1.txt AC 1,800 ms
23,928 KB
evil_big_2.txt AC 1,847 ms
23,844 KB
evil_big_3.txt AC 1,868 ms
23,832 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N;
  cin>>N;
  vector<int>A(N);
  for(auto &i:A)cin>>i;
  int t=0;
  for(int i:A)t^=i;
  vector<set<int>>b(17);
  for(int i=0;i<N;i++){
    for(int j=0;j<17;j++){
      if(A[i]>>j&1)b[j].insert(i);
    }
  }
  int p=0;
  if(t){
    cout<<1<<endl;
    p=1;
  }else{
    cout<<0<<endl;
  }
  int ret=0;
  while(ret!=-1){
    if(p){
      int k=0;
      for(int i=0;i<17;i++){
        if(t>>i&1)k=i;
      }
      int I=*b[k].begin(),K=A[I]-(A[I]^t);
      for(int i=0;i<17;i++){
        b[i].erase(I);
      }
      t^=A[I];
      A[I]-=K;
      t^=A[I];
      for(int i=0;i<17;i++){
        if(A[I]>>i&1)b[i].insert(I);
      }
      cout<<I+1<<' '<<K<<endl;
    }else{
      int I,K;
      cin>>I>>K;
      --I;
      for(int i=0;i<17;i++){
        b[i].erase(I);
      }
      t^=A[I];
      A[I]-=K;
      t^=A[I];
      for(int i=0;i<17;i++){
        if(A[I]>>i&1)b[i].insert(I);
      }
    }
    p=1-p;
    cin>>ret;
    //for(int i:A)cout<<i<<' ';cout<<endl;
  }
}
0