結果

問題 No.153 石の山
ユーザー ChiakiYokoyamaChiakiYokoyama
提出日時 2019-10-28 23:44:12
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,355 bytes
コンパイル時間 1,436 ms
コンパイル使用メモリ 164,328 KB
実行使用メモリ 4,480 KB
最終ジャッジ日時 2023-10-12 23:14:11
合計ジャッジ時間 2,620 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,352 KB
testcase_03 AC 1 ms
4,352 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,480 KB
testcase_06 AC 1 ms
4,352 KB
testcase_07 AC 2 ms
4,352 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 1 ms
4,352 KB
testcase_12 AC 2 ms
4,352 KB
testcase_13 AC 2 ms
4,352 KB
testcase_14 AC 2 ms
4,352 KB
testcase_15 AC 1 ms
4,348 KB
testcase_16 AC 2 ms
4,348 KB
testcase_17 AC 2 ms
4,372 KB
testcase_18 AC 2 ms
4,352 KB
testcase_19 AC 2 ms
4,348 KB
testcase_20 AC 2 ms
4,352 KB
testcase_21 AC 2 ms
4,352 KB
testcase_22 AC 1 ms
4,352 KB
testcase_23 AC 2 ms
4,352 KB
testcase_24 AC 2 ms
4,352 KB
testcase_25 AC 2 ms
4,352 KB
testcase_26 AC 2 ms
4,348 KB
testcase_27 AC 2 ms
4,348 KB
testcase_28 AC 2 ms
4,352 KB
testcase_29 AC 2 ms
4,352 KB
testcase_30 AC 1 ms
4,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))

#define INF 2e9
#define INF_LL 1LL<<60
#define ll long long

typedef pair<ll, ll> P;

int nim[101]; 
/* nim[i]: 石がi個ある状態でのgrundy数 */

int main(){
    int n; cin >> n;

    nim[2] = 1;

    REPN(i, 3, n+1) {
        int a=0, b=0;

        if(i % 2 == 0) {
            a = nim[i/2]^nim[i/2];
        } else {
            a = nim[(i+1)/2];
            a ^= nim[(i-1)/2];
        }

        if(i % 3 == 0) {
            b = nim[i/3]^nim[i/3]^nim[i/3];
        } else if (i % 3 == 1) {
            b = nim[(i-1)/3]^nim[(i-1)/3];
            b ^= nim[(i+2)/3];
        } else {
            b = nim[(i-2)/3];
            b ^= nim[(i+1)/3]^nim[(i+1)/3];
        }

        if(b < a) {
            int tmp = b;
            b = a;
            a = tmp;    
        }

        REP(j, b+2) {
            if(j != a && j != b) {
                nim[i] = j;
                break;
            }
        }
    }

    if(nim[n] == 0) {
        cout << "B" << endl;
    } else {
        cout << "A" << endl;
    }

    
    return 0;
}
0