結果
| 問題 |
No.153 石の山
|
| コンテスト | |
| ユーザー |
nvt4s
|
| 提出日時 | 2019-04-30 03:36:59 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 3 ms / 5,000 ms |
| コード長 | 938 bytes |
| コンパイル時間 | 2,932 ms |
| コンパイル使用メモリ | 165,860 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-12-26 00:40:15 |
| 合計ジャッジ時間 | 4,137 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 27 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll INFL = 1000000000000000010;//10^18 = 2^60
int INF = 2000000000;//10^9
ll MOD = 998244353;
vector<int> memo(110, -1);
int grundy(int N){
if(memo.at(N) != -1) return memo.at(N);
if(N == 1) return 0;
if(N == 2) return 1;
set<int> s;
if(N % 2 == 0){
s.insert(grundy(N/2) ^ grundy(N/2));
}else{
s.insert(grundy(N/2) ^ grundy(N/2+1));
}
if(N % 3 == 1){
s.insert(grundy(N/3) ^ grundy(N/3) ^ grundy(N/3+1));
}else if(N % 3 == 2){
s.insert(grundy(N/3) ^ grundy(N/3+1) ^ grundy(N/3+1));
}else{
s.insert(grundy(N/3) ^ grundy(N/3) ^ grundy(N/3));
}
int res = 0;
while(s.count(res)) res++;
return memo.at(N) = res;
}
int main() {
int N;
cin >> N;
if(grundy(N)){
cout << "A" << endl;
}else{
cout << "B" << endl;
}
}
nvt4s