結果
問題 | No.7 プライムナンバーゲーム |
ユーザー |
![]() |
提出日時 | 2016-09-14 12:39:41 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 240 ms / 5,000 ms |
コード長 | 603 bytes |
コンパイル時間 | 589 ms |
コンパイル使用メモリ | 62,812 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-10-01 15:48:35 |
合計ジャッジ時間 | 2,689 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 17 |
ソースコード
#include <iostream> #include <set> using namespace std; int N; bool so[10001]; int mem[10001]; int grundy(int n) { if (mem[n] != -1)return mem[n]; set<int> s; for (int i = 2; i <= n; i++) { if (!so[i] && n - i > 1) s.insert(grundy(n - i)); } int res = 0; while (s.count(res)) res++; return mem[n] = res; } int main() { cin >> N; for (int i = 2; i <= 10000; i++) { if (!so[i]) { for (int j = i * 2; j <= 10000; j += i) so[j] = true; } } for (int i = 0; i < 10001; i++) mem[i] = -1; if (grundy(N)) { cout << "Win" << endl; } else { cout << "Lose" << endl; } return 0; }