結果

問題 No.2165 Let's Play Nim!
ユーザー tko919tko919
提出日時 2022-12-16 00:30:22
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 199 ms / 2,000 ms
コード長 1,853 bytes
コンパイル時間 3,229 ms
コンパイル使用メモリ 209,504 KB
実行使用メモリ 24,252 KB
平均クエリ数 863.56
最終ジャッジ日時 2023-08-09 09:45:55
合計ジャッジ時間 17,823 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 32 ms
23,544 KB
testcase_01 AC 132 ms
23,232 KB
testcase_02 AC 142 ms
23,388 KB
testcase_03 AC 90 ms
23,808 KB
testcase_04 AC 25 ms
23,388 KB
testcase_05 AC 31 ms
24,228 KB
testcase_06 AC 31 ms
23,388 KB
testcase_07 AC 28 ms
24,072 KB
testcase_08 AC 93 ms
24,216 KB
testcase_09 AC 26 ms
24,252 KB
testcase_10 AC 34 ms
23,496 KB
testcase_11 AC 142 ms
23,496 KB
testcase_12 AC 123 ms
23,400 KB
testcase_13 AC 25 ms
23,208 KB
testcase_14 AC 30 ms
24,156 KB
testcase_15 AC 27 ms
23,820 KB
testcase_16 AC 115 ms
23,844 KB
testcase_17 AC 63 ms
24,168 KB
testcase_18 AC 199 ms
23,892 KB
testcase_19 AC 25 ms
23,388 KB
testcase_20 AC 31 ms
23,472 KB
testcase_21 AC 55 ms
23,376 KB
testcase_22 AC 45 ms
24,216 KB
testcase_23 AC 43 ms
23,388 KB
testcase_24 AC 40 ms
23,460 KB
testcase_25 AC 81 ms
23,880 KB
testcase_26 AC 142 ms
23,256 KB
testcase_27 AC 48 ms
23,256 KB
testcase_28 AC 70 ms
23,424 KB
testcase_29 AC 25 ms
23,472 KB
testcase_30 AC 25 ms
23,208 KB
testcase_31 AC 24 ms
23,868 KB
testcase_32 AC 94 ms
24,036 KB
evil_2_big_1.txt AC 1,634 ms
24,132 KB
evil_2_big_2.txt AC 1,858 ms
23,988 KB
evil_2_big_3.txt AC 1,654 ms
23,652 KB
evil_big_1.txt AC 1,783 ms
23,856 KB
evil_big_2.txt AC 1,879 ms
24,180 KB
evil_big_3.txt AC 1,872 ms
24,048 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0