結果

問題 No.7 プライムナンバーゲーム
ユーザー lioolioo
提出日時 2021-03-31 18:04:21
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 7 ms / 5,000 ms
コード長 716 bytes
コンパイル時間 648 ms
コンパイル使用メモリ 70,336 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-09 05:03:15
合計ジャッジ時間 1,550 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,820 KB
testcase_01 AC 2 ms
6,948 KB
testcase_02 AC 7 ms
6,944 KB
testcase_03 AC 2 ms
6,948 KB
testcase_04 AC 2 ms
6,948 KB
testcase_05 AC 2 ms
6,948 KB
testcase_06 AC 4 ms
6,948 KB
testcase_07 AC 3 ms
6,944 KB
testcase_08 AC 3 ms
6,948 KB
testcase_09 AC 4 ms
6,948 KB
testcase_10 AC 2 ms
6,944 KB
testcase_11 AC 3 ms
6,944 KB
testcase_12 AC 6 ms
6,944 KB
testcase_13 AC 6 ms
6,944 KB
testcase_14 AC 7 ms
6,948 KB
testcase_15 AC 7 ms
6,948 KB
testcase_16 AC 7 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>

using namespace std;

vector<int> prime;

int main(){
    bool iswin[10005]={};
    int N;
    cin>>N;

    prime.push_back(2);
    for(int i=3;i<=N;i+=2){
        for(int j=0;j<prime.size();j++){
            if(i%prime[j]==0)break;
            if(j==prime.size()-1){
                prime.push_back(i);
            }
        }
    }

    iswin[0]=iswin[1]=1;
    for(int i=2;i<=N;i++){
        for(int j=0;j<prime.size();j++){
            if(i-prime[j]<0)break;
            if(!iswin[i-prime[j]]){
                iswin[i]=true;
                break;
            }
        }
    }

    if(iswin[N]){
        cout<<"Win"<<endl;
    } else {
        cout<<"Lose"<<endl;
    }
}
0