結果
| 問題 |
No.7 プライムナンバーゲーム
|
| コンテスト | |
| ユーザー |
tottoripaper
|
| 提出日時 | 2014-11-16 02:44:31 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 8 ms / 5,000 ms |
| コード長 | 992 bytes |
| コンパイル時間 | 189 ms |
| コンパイル使用メモリ | 35,008 KB |
| 実行使用メモリ | 6,824 KB |
| 最終ジャッジ日時 | 2024-10-01 15:28:08 |
| 合計ジャッジ時間 | 835 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 17 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:38:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
38 | scanf("%d", &N);
| ~~~~~^~~~~~~~~~
ソースコード
#include <algorithm>
#include <cstdio>
int N;
bool isPrime[10011];
int primes[10011], p_length, memo[10001];
// rec(n): 自分にnで回ってきたとき勝てるか
bool rec(int n){
if(n <= 1){return true;}
if(memo[n] != -1){return memo[n];}
int maxIndex = std::upper_bound(primes, primes+p_length, n) - primes;
bool f = false;
for(int i=0;i<maxIndex;i++){
f = f || !rec(n-primes[i]);
}
return memo[n] = f;
}
int main(){
std::fill(isPrime, isPrime+10011, true);
primes[0] = 2;
for(int i=4;i<=10010;i+=2){isPrime[i] = false;}
p_length = 1;
for(int i=3;i<=10010;i+=2){
if(isPrime[i]){
primes[p_length++] = i;
for(int j=i*i;j<=10010;j+=i){
isPrime[j] = false;
}
}
}
scanf("%d", &N);
std::fill(memo, memo+10001, -1);
if(rec(N)){
puts("Win");
}else{
puts("Lose");
}
}
tottoripaper