結果
問題 | No.7 プライムナンバーゲーム |
ユーザー |
![]() |
提出日時 | 2016-02-24 17:52:34 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 26 ms / 5,000 ms |
コード長 | 806 bytes |
コンパイル時間 | 533 ms |
コンパイル使用メモリ | 60,480 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-10-01 15:40:58 |
合計ジャッジ時間 | 1,467 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 17 |
ソースコード
#include<iostream> #include<vector> using namespace std; #define NMAX 10000 #define NO -1 #define WIN 0 #define LOSE 1 int main(){ int N; bool hurui[NMAX+1]; vector<int> primenumber; int winlose[NMAX+1]; for(int i=0;i<=NMAX;i++) hurui[i]=true; hurui[0]=false; hurui[1]=false; for(int i=0;i<=NMAX;i++){ if(hurui[i]){ primenumber.push_back(i); for(int j=i;j<NMAX;j+=i){ hurui[j]=false; } } } for(int i=0;i<=NMAX;i++) winlose[i]=NO; winlose[2]=LOSE; winlose[3]=LOSE; for(int i=0;i<=NMAX;i++){ if(winlose[i]!=NO){ for(int j=0;j<primenumber.size();j++){ if(i+primenumber[j]>NMAX) break; if(winlose[i+primenumber[j]]==WIN) continue; winlose[i+primenumber[j]]=(winlose[i]==WIN)?LOSE:WIN; } } } cin>>N; cout<<((winlose[N]==WIN)?"Win":"Lose")<<endl; }