結果

問題 No.3120 Lower Nim
ユーザー ponjuice
提出日時 2025-04-17 12:24:46
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 210 ms / 2,000 ms
コード長 1,265 bytes
コンパイル時間 3,190 ms
コンパイル使用メモリ 275,780 KB
実行使用メモリ 25,844 KB
平均クエリ数 2685.91
最終ジャッジ日時 2025-04-17 12:24:57
合計ジャッジ時間 11,054 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 43
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (int i = a; i < (b); i++)

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, 0, n) cin >> a[i];
    
    int xr = 0;
    rep(i, 0, n) xr ^= a[i];

    int res = 0;

    // xorが0の時のみ後手必勝
    if (xr == 0) {
        cout << "Second" << endl;
        int i, x;
        cin >> i >> x;
        cin >> res;
        i--;

        xr ^= a[i];
        a[i] -= x;
        xr ^= a[i];
    } else {
        cout << "First" << endl;
    }

    while(res == 0) {
        // xorの最下位bitを選び、それを超えるA[i] を選ぶ
        int select = 0;
        rep(i, 0, 20) {
            if((xr >> i) & 1) {
                select = 1 << i;
                break;
            }
        }
        rep(i, 0, n) {
            if(a[i] >= select) {
                cout << i + 1 << " " << select << endl;

                xr ^= a[i];
                a[i] -= select;
                xr ^= a[i];
                break;
            }
        }
        cin >> res;
        if(res == -1 || res == 1) {
            break;
        }
        int i, x;
        cin >> i >> x;
        i--;
        cin >> res;

        xr ^= a[i];
        a[i] -= x;
        xr ^= a[i];
    }
}
0