結果
問題 | No.7 プライムナンバーゲーム |
ユーザー |
![]() |
提出日時 | 2015-01-07 23:54:02 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 163 ms / 5,000 ms |
コード長 | 863 bytes |
コンパイル時間 | 840 ms |
コンパイル使用メモリ | 84,236 KB |
実行使用メモリ | 6,824 KB |
最終ジャッジ日時 | 2024-10-01 15:28:52 |
合計ジャッジ時間 | 2,627 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 17 |
ソースコード
#include <iostream> #include <vector> #include <cstdio> #include <sstream> #include <map> #include <string> #include <algorithm> #include <queue> #include <set> #include <cmath> using namespace std; int grundy(vector<int> &memo, vector<int> &p, int N){ if(memo[N] >= 0) return memo[N]; set<int> s; for(int i=0; i<p.size(); i++){ if(N-p[i] < 2) break; s.insert( grundy(memo, p, N-p[i]) ); } int ret = 0; while(s.count(ret) != 0){ ret++; } memo[N] = ret; return ret; } int main(){ int N; cin >> N; vector<bool> is_P(N+1, true); is_P[0] = is_P[1] = false; vector<int> prime; for(int i=2; i<=N; i++){ if(is_P[i] == false) continue; prime.push_back(i); for(int j=i+i; j<=N; j+=i){ is_P[j] = false; } } vector<int> memo(N+1, -1); memo[0] = memo[1] = 0; cout << (grundy(memo, prime, N) == 0 ? "Lose":"Win") << endl; return 0; }