結果
問題 | No.7 プライムナンバーゲーム |
ユーザー |
![]() |
提出日時 | 2018-06-24 04:31:09 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 4 ms / 5,000 ms |
コード長 | 755 bytes |
コンパイル時間 | 713 ms |
コンパイル使用メモリ | 80,076 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-10-01 16:13:13 |
合計ジャッジ時間 | 1,357 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 17 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:20:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 20 | scanf("%d", &n); | ~~~~~^~~~~~~~~~
ソースコード
#include <cstdio> #include <cstring> #include <iostream> #include <string> #include <cmath> #include <bitset> #include <vector> #include <map> #include <set> #include <queue> #include <deque> #include <algorithm> using namespace std; typedef long long int ll; int main() { int n; scanf("%d", &n); vector<int> p; p.push_back(2); for(int i=3; i<=n+100; i+=2){ bool e=0; for(int j=3; j*j<=i; j+=2){ if(i%j==0){ e=1; break; } } if(e==0){ p.push_back(i); } } bool dp[10001]; dp[0]=0, dp[1]=0; int t=0; for(int i=2; i<=n; i++){ if(p[t+1]<=i) t++; dp[i]=1; for(int j=0; j<=t; j++){ if(dp[i-p[j]]==1){ dp[i]=0; break; } } } if(dp[n]==0){ printf("Win\n"); }else{ printf("Lose\n"); } return 0; }