結果

問題 No.2165 Let's Play Nim!
ユーザー 👑 Nachia
提出日時 2022-12-16 00:07:25
言語 C++17(gcc12)
(gcc 12.3.0 + boost 1.87.0)
結果
QLE  
実行時間 -
コード長 1,545 bytes
コンパイル時間 2,789 ms
コンパイル使用メモリ 132,376 KB
最終ジャッジ日時 2025-02-09 14:01:57
ジャッジサーバーID
(参考情報)
judge5 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample QLE * 1
other AC * 1 WA * 7 RE * 3 QLE * 27
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <atcoder/modint>
#include <atcoder/segtree>

using namespace std;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
const i64 INF = 1001001001001001001;

using Modint = atcoder::static_modint<998244353>;

namespace Segtree {
    using S = pair<int,int>;
    S e(){ return {-1,-1}; }
    S op(S l, S r){ return max(l, r); }
    using RQ = atcoder::segtree<S, op, e>;
}

int main(){
    int N; cin >> N;
    vector<int> A(N); rep(i,N) cin >> A[i];
    Segtree::RQ rq(N);
    rep(i,N) rq.set(i, {A[i],i});

    int allxor = 0;
    for(int a : A) allxor ^= a;

    auto readMove = [&](){
        int i,k; cin >> i >> k; i--;
        allxor ^= A[i];
        A[i] -= k;
        rq.set(i, {A[i],i});
        allxor ^= A[i];
    };

    auto doMove = [&](){
        int i = rq.all_prod().second;
        allxor ^= A[i];
        int k = A[i] - allxor;
        cout << (i+1) << ' ' << k << endl;
        A[i] -= k;
        rq.set(i, {A[i],i});
        allxor ^= A[i];
    };

    if(allxor != 0){
        cout << 1 << endl;
    } else {
        cout << 0 << endl;
        readMove();
    }

    while(true){
        doMove();
        int r; cin >> r;
        if(r <= 0) break;
        readMove();
    }
    return 0;
}


struct ios_do_not_sync{
    ios_do_not_sync(){
        ios::sync_with_stdio(false);
        cin.tie(nullptr);
    }
} ios_do_not_sync_instance;


0