結果
問題 | No.7 プライムナンバーゲーム |
ユーザー |
![]() |
提出日時 | 2016-03-24 17:52:03 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 12 ms / 5,000 ms |
コード長 | 713 bytes |
コンパイル時間 | 511 ms |
コンパイル使用メモリ | 60,656 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-10-01 15:42:10 |
合計ジャッジ時間 | 1,123 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 17 |
ソースコード
#include <iostream> #include <vector> #include <numeric> using namespace std; #define MAX 10001 vector<int> prime; void Eratosthenes(){ bool arr[MAX]; fill(arr,arr + MAX,false); prime.push_back(2); for(int i = 4;i < MAX;i += 2) arr[i] = true; for(int i = 3;i < MAX;i += 2){ if(arr[i]) continue; prime.push_back(i); for(int j = i + i;j < MAX;j += i) arr[j] = true; } } int main(){ Eratosthenes(); bool dp[MAX]; fill(dp,dp + MAX,false); dp[0] = dp[1] = true; int n; cin >> n; for(int i = 2;i <= n;i++){ for(int j : prime){ if(i - j < 0) break; else dp[i] |= !dp[i - j]; } } cout << (dp[n] ? "Win" : "Lose") << endl; }