結果

問題 No.2165 Let's Play Nim!
ユーザー umezoumezo
提出日時 2022-12-16 01:53:19
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 193 ms / 2,000 ms
コード長 1,832 bytes
コンパイル時間 2,434 ms
コンパイル使用メモリ 210,040 KB
実行使用メモリ 24,276 KB
平均クエリ数 863.56
最終ジャッジ日時 2023-08-09 11:03:08
合計ジャッジ時間 17,721 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 32 ms
23,640 KB
testcase_01 AC 132 ms
23,592 KB
testcase_02 AC 142 ms
23,352 KB
testcase_03 AC 88 ms
23,364 KB
testcase_04 AC 26 ms
24,276 KB
testcase_05 AC 31 ms
23,484 KB
testcase_06 AC 31 ms
24,276 KB
testcase_07 AC 30 ms
23,184 KB
testcase_08 AC 96 ms
23,808 KB
testcase_09 AC 28 ms
23,508 KB
testcase_10 AC 36 ms
23,388 KB
testcase_11 AC 141 ms
23,976 KB
testcase_12 AC 122 ms
23,580 KB
testcase_13 AC 26 ms
23,376 KB
testcase_14 AC 31 ms
23,496 KB
testcase_15 AC 28 ms
23,628 KB
testcase_16 AC 115 ms
23,364 KB
testcase_17 AC 64 ms
24,036 KB
testcase_18 AC 193 ms
23,904 KB
testcase_19 AC 26 ms
23,340 KB
testcase_20 AC 31 ms
23,340 KB
testcase_21 AC 54 ms
23,628 KB
testcase_22 AC 45 ms
23,496 KB
testcase_23 AC 42 ms
23,388 KB
testcase_24 AC 39 ms
23,604 KB
testcase_25 AC 79 ms
24,252 KB
testcase_26 AC 143 ms
23,592 KB
testcase_27 AC 47 ms
23,592 KB
testcase_28 AC 69 ms
23,628 KB
testcase_29 AC 24 ms
23,388 KB
testcase_30 AC 24 ms
23,916 KB
testcase_31 AC 24 ms
23,496 KB
testcase_32 AC 95 ms
23,352 KB
evil_2_big_1.txt AC 1,626 ms
23,340 KB
evil_2_big_2.txt AC 1,782 ms
23,808 KB
evil_2_big_3.txt AC 1,621 ms
23,964 KB
evil_big_1.txt AC 1,783 ms
23,376 KB
evil_big_2.txt AC 1,805 ms
23,628 KB
evil_big_3.txt AC 1,852 ms
24,036 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘int main()’ 内:
main.cpp:68:11: 警告: ‘tmp’ may be used uninitialized [-Wmaybe-uninitialized]
   68 |       int tmp;
      |           ^~~
main.cpp:45:11: 警告: ‘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