結果
| 問題 |
No.153 石の山
|
| コンテスト | |
| ユーザー |
not_522
|
| 提出日時 | 2015-08-16 09:43:36 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 5,000 ms |
| コード長 | 980 bytes |
| コンパイル時間 | 1,588 ms |
| コンパイル使用メモリ | 176,540 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-10-14 14:39:31 |
| 合計ジャッジ時間 | 2,765 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 27 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
template<typename T> class Grundy {
private:
map<T, int> grundy;
template<typename S> int solve(S s) {
int g = 0;
for (auto t : s) g ^= solve(t);
return g;
}
public:
int solve(T t) {
if (grundy.count(t)) return grundy[t];
set<int> s;
for (auto g : t.next()) s.insert(solve(g));
for (int i = 0; ; ++i) {
if (s.count(i) == 0) return grundy[t] = i;
}
}
};
class State {
private:
int n;
public:
State (int n) : n(n) {}
vector<vector<State>> next() {
vector<vector<State>> v;
if (n >= 2) v.emplace_back(vector<State>({State(n / 2), State((n + 1) / 2)}));
if (n >= 3) v.emplace_back(vector<State>({State(n / 3), State((n + 1) / 3), State((n + 2) / 3)}));
return v;
}
bool operator<(const State& state) const {
return n < state.n;
}
};
int main() {
int n;
cin >> n;
Grundy<State> grundy;
cout << (grundy.solve(State(n)) ? "A" : "B") << endl;
}
not_522