結果
問題 |
No.361 門松ゲーム2
|
ユーザー |
![]() |
提出日時 | 2016-09-13 22:49:24 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 160 ms / 2,000 ms |
コード長 | 1,397 bytes |
コンパイル時間 | 1,969 ms |
コンパイル使用メモリ | 174,960 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-11-17 05:07:59 |
合計ジャッジ時間 | 3,232 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 28 |
ソースコード
#include <bits/stdc++.h> using namespace std; #define rep(i, j) for(int i=0; i < (int)(j); i++) #define repeat(i, j, k) for(int i = (j); i < (int)(k); i++) template<class T> istream& operator >> (istream &is , vector<T> &v) { for(T &a : v) is >> a; return is; } class Solver { public: int L, D; vector<int> grundy; int calc_grundy(int l) { if(grundy[l] >= 0) return grundy[l]; if(l < 6) { return grundy[l] = 0; } else { set<int> reachable; repeat(L1, 1, l + 1) { repeat(L2, L1 + 1, l - L1 + 1) { int L3 = l - L1 - L2; if(L3 <= L2 or L3 - L1 > D) continue; reachable.insert(calc_grundy(L1) ^ calc_grundy(L2) ^ calc_grundy(L3)); } } if(reachable.size() == 0) { return grundy[l] = 0; } int mex = 0; for(int g : reachable) { if(mex == g) mex++; } return grundy[l] = mex; } } bool solve() { cin >> L >> D; grundy.resize(L + 1, -1); cout << (calc_grundy(L) != 0 ? "kado" : "matsu") << endl; return 0; } }; int main() { cin.tie(0); ios::sync_with_stdio(false); Solver s; s.solve(); return 0; }