結果
問題 | No.153 石の山 |
ユーザー |
![]() |
提出日時 | 2020-08-07 18:03:12 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 5,000 ms |
コード長 | 1,138 bytes |
コンパイル時間 | 2,288 ms |
コンパイル使用メモリ | 200,964 KB |
最終ジャッジ日時 | 2025-01-12 15:47:11 |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 27 |
ソースコード
#include <bits/stdc++.h> #define rep(a,n) for (ll a = 0; a < (n); ++a) using namespace std; using ll = long long; typedef pair<ll,ll> P; typedef pair<P,ll> PP; typedef vector<vector<ll> > Graph; template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } const ll INF = 1e18; //入力 ll n; vector<ll>g; ll grundy(ll n){ if(g[n]>=0)return g[n]; set<ll>st; if(n>=2){ if(n%2==1){ st.insert(grundy(n/2)^grundy(n/2+1)); } else{ st.insert(grundy(n/2)^grundy(n/2)); } } if(n>=3){ if(n%3==0){ st.insert(grundy(n/3)); } if(n%3==1){ st.insert(grundy(n/3+1)); } if(n%3==2){ st.insert(grundy(n/3)); } } ll res = 0; while(st.count(res))res++; return g[n]=res; } int main(){ cin >> n; g.resize(n+1,-1); g[0]=0; if(grundy(n)==0){ cout << 'B' << endl; } else{ cout << 'A' << endl; } return 0; }