結果

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

ソースコード

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();
        int r; cin >> r;
        if(r == -1) return 0;
    }

    while(true){
        doMove();
        readMove();
        int r; cin >> r;
        if(r == -1) break;
    }
    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