結果

問題 No.7 プライムナンバーゲーム
ユーザー NagisaNagisa
提出日時 2016-07-20 07:13:01
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 1,383 ms / 5,000 ms
コード長 769 bytes
コンパイル時間 1,717 ms
コンパイル使用メモリ 165,900 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-09 04:01:56
合計ジャッジ時間 10,718 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 1,383 ms
6,948 KB
testcase_03 AC 37 ms
6,948 KB
testcase_04 AC 8 ms
6,944 KB
testcase_05 AC 8 ms
6,944 KB
testcase_06 AC 276 ms
6,944 KB
testcase_07 AC 163 ms
6,944 KB
testcase_08 AC 56 ms
6,948 KB
testcase_09 AC 484 ms
6,948 KB
testcase_10 AC 2 ms
6,944 KB
testcase_11 AC 165 ms
6,944 KB
testcase_12 AC 904 ms
6,948 KB
testcase_13 AC 982 ms
6,944 KB
testcase_14 AC 1,382 ms
6,944 KB
testcase_15 AC 1,290 ms
6,944 KB
testcase_16 AC 1,164 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define REP(i,n) for(int i = 0; i < (int)(n); ++i)
using namespace std;

vector<int> prime(int N){
    vector<int> v;
    v.push_back(2);
    for(int i=3; i<=N; i+=2){
        bool flag = true;
        for(int j=3; j<=sqrt(i); j+=2){
            if(i%j==0){
                flag = false;
                break;
            }
        }
        if (flag==true) v.push_back(i);
    }
    return v;
}

int main(){
    int N;
    cin >> N;
    bool dp[N+1];
    dp[0] = true;
    dp[1] = true;
    for(int i=2; i<=N; i++){
        dp[i] = false;
        for(int p: prime(i)){
            if(dp[i-p]==false){
                dp[i] = true;
                break;
            }
        }
    }
    cout << (dp[N]?"Win":"Lose") << endl;
    return 0;
}
0