結果
問題 | No.153 石の山 |
ユーザー |
![]() |
提出日時 | 2016-09-29 21:56:12 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 5,000 ms |
コード長 | 1,326 bytes |
コンパイル時間 | 1,466 ms |
コンパイル使用メモリ | 168,724 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-11-21 10:40:12 |
合計ジャッジ時間 | 2,292 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 27 |
ソースコード
#include <bits/stdc++.h>using namespace std;namespace {typedef double real;typedef long long ll;template<class T> ostream& operator<<(ostream& os, const vector<T>& vs) {if (vs.empty()) return os << "[]";auto i = vs.begin();os << "[" << *i;for (++i; i != vs.end(); ++i) os << " " << *i;return os << "]";}template<class T> istream& operator>>(istream& is, vector<T>& vs) {for (auto it = vs.begin(); it != vs.end(); it++) is >> *it;return is;}int N;void input() {cin >> N;}int cache[105];int gr(int n) {if (cache[n] >= 0) return cache[n];vector<int> st(101, 0);int x, y, z;// div 2x = n / 2;y = n - x;int a = gr(x) ^ gr(y);st[a] = true;// div 3x = n / 3;y = (n - x) / 2;z = n - x - y;int b = gr(x) ^ gr(y) ^ gr(z);st[b] = true;for (int i = 0; ; i++) {if (not st[i]) return cache[n] = i;}}void solve() {memset(cache, -1, sizeof(cache));cache[1] = 0;cache[2] = 1;cache[3] = 2;cout << (gr(N) == 0 ? "B" : "A") << endl;}}int main() {input(); solve();return 0;}