結果

問題 No.2165 Let's Play Nim!
ユーザー t98slidert98slider
提出日時 2022-12-16 04:33:14
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,249 bytes
コンパイル時間 2,278 ms
コンパイル使用メモリ 175,964 KB
実行使用メモリ 24,588 KB
平均クエリ数 214.15
最終ジャッジ日時 2023-08-09 13:29:58
合計ジャッジ時間 13,057 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
24,480 KB
testcase_01 AC 135 ms
23,460 KB
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 AC 98 ms
23,700 KB
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 AC 56 ms
23,448 KB
testcase_22 AC 49 ms
23,664 KB
testcase_23 AC 44 ms
24,384 KB
testcase_24 AC 40 ms
23,700 KB
testcase_25 AC 80 ms
23,592 KB
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 AC 25 ms
24,084 KB
testcase_31 RE -
testcase_32 RE -
evil_2_big_1.txt RE -
evil_2_big_2.txt RE -
evil_2_big_3.txt RE -
evil_big_1.txt AC 1,773 ms
23,688 KB
evil_big_2.txt RE -
evil_big_3.txt RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, v = 0, p, x, s, M = 18;
    cin >> n;
    vector<int> a(n);
    vector<set<int>> S(M);
    for(int i = 0; i < M; i++)S[i].insert(1 << 30);
    for(int i = 0; i < n; i++){
        cin >> a[i];
        v ^= a[i];
        for(int j = 0; j < M; j++){
            if(a[i] >> j & 1)S[j].insert(i);
        }
    }
    auto update = [&](int p, int x){
        v ^= a[p];
        for(int j = 0; j < M; j++){
            if(a[p] >> j & 1)S[j].erase(p);
        }
        a[p] -= x;
        v ^= a[p];
        for(int j = 0; j < M; j++){
            if(a[p] >> j & 1)S[j].insert(p);
        }
    };
    auto my_turn = [&](){
        int p = *S[__lg(v)].begin();
        while((v ^ a[p]) >= a[p]) ;
        cout << p + 1 << " " << a[p] - (v ^ a[p]) << endl;
        update(p, a[p] - (v ^ a[p]));
    };
    if(v == 0){
        cout << 0 << endl;
        cin >> p >> x;
        update(--p, x);
    }else{
        cout << 1 << endl;
        my_turn();
    }
    while(true){
        cin >> s;
        if(s == -1)return 0;
        my_turn();
        cin >> s;
        if(s == -1)return 0;
        cin >> p >> x;
        update(--p, x);
    }
}
0