結果

問題 No.2165 Let's Play Nim!
ユーザー 👑 NachiaNachia
提出日時 2022-12-16 00:29:19
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 186 ms / 2,000 ms
コード長 2,653 bytes
コンパイル時間 2,565 ms
コンパイル使用メモリ 81,520 KB
実行使用メモリ 24,276 KB
平均クエリ数 863.56
最終ジャッジ日時 2023-08-09 09:44:30
合計ジャッジ時間 15,408 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 28 ms
24,228 KB
testcase_01 AC 120 ms
23,820 KB
testcase_02 AC 134 ms
23,664 KB
testcase_03 AC 86 ms
23,532 KB
testcase_04 AC 24 ms
23,928 KB
testcase_05 AC 31 ms
23,652 KB
testcase_06 AC 30 ms
23,388 KB
testcase_07 AC 30 ms
23,412 KB
testcase_08 AC 91 ms
23,664 KB
testcase_09 AC 26 ms
23,388 KB
testcase_10 AC 33 ms
23,928 KB
testcase_11 AC 133 ms
24,072 KB
testcase_12 AC 111 ms
23,544 KB
testcase_13 AC 24 ms
24,276 KB
testcase_14 AC 30 ms
24,252 KB
testcase_15 AC 26 ms
23,880 KB
testcase_16 AC 110 ms
23,664 KB
testcase_17 AC 61 ms
23,928 KB
testcase_18 AC 186 ms
23,388 KB
testcase_19 AC 25 ms
23,616 KB
testcase_20 AC 28 ms
23,388 KB
testcase_21 AC 52 ms
24,276 KB
testcase_22 AC 44 ms
23,832 KB
testcase_23 AC 42 ms
24,276 KB
testcase_24 AC 37 ms
23,904 KB
testcase_25 AC 75 ms
24,036 KB
testcase_26 AC 131 ms
24,216 KB
testcase_27 AC 46 ms
23,532 KB
testcase_28 AC 66 ms
23,832 KB
testcase_29 AC 23 ms
24,036 KB
testcase_30 AC 24 ms
23,844 KB
testcase_31 AC 24 ms
24,024 KB
testcase_32 AC 88 ms
24,024 KB
evil_2_big_1.txt AC 1,505 ms
23,544 KB
evil_2_big_2.txt AC 1,713 ms
24,288 KB
evil_2_big_3.txt AC 1,505 ms
23,640 KB
evil_big_1.txt AC 1,641 ms
23,664 KB
evil_big_2.txt AC 1,707 ms
24,144 KB
evil_big_3.txt AC 1,715 ms
24,288 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#line 1 "Main.cpp"
#line 1 "Main.cpp"
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <atcoder/modint>
#include <atcoder/segtree>
#line 1 "nachia\\misc\\bit-operations.hpp"

#line 4 "nachia\\misc\\bit-operations.hpp"


namespace nachia{

    int Popcount(unsigned long long c) noexcept {
    #ifdef __GNUC__
        return __builtin_popcountll(c);
    #else
        c = (c & (~0ull/3)) + ((c >> 1) & (~0ull/3));
        c = (c & (~0ull/5)) + ((c >> 2) & (~0ull/5));
        c = (c & (~0ull/17)) + ((c >> 4) & (~0ull/17));
        c = (c * (~0ull/257)) >> 56;
        return c;
    #endif
    }

    // please ensure x != 0
    int MsbIndex(unsigned long long x) noexcept {
    #ifdef __GNUC__
        return 63 - __builtin_clzll(x);
    #else
        int res = 0;
        for(int d=32; d>=0; d>>=1) if(x >> d){ res |= d; x >>= d; }
        return res;
    #endif
    }

    // please ensure x != 0
    int LsbIndex(unsigned long long x) noexcept {
    #ifdef __GNUC__
        return __builtin_ctzll(x);
    #else
        return msb_idx(x & -x);
    #endif
    }

}

#line 9 "Main.cpp"

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 = int;
    S e(){ return 0; }
    S op(S l, S r){ return 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(A);

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

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

    auto doMove = [&](){
        int msb = 1 << nachia::MsbIndex(allxor);
        int i = rq.max_right(0, [&](int x){ return 0 == (msb & x); });
        allxor ^= A[i];
        int k = A[i] - allxor;
        cout << (i+1) << ' ' << k << endl;
        A[i] -= k;
        rq.set(i, A[i]);
        allxor ^= A[i];
        int r; cin >> r;
        return r == -1;
    };

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

    while(true){
        if(doMove()) return 0;
        if(readMove()) return 0;
    }
    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