結果

問題 No.7 プライムナンバーゲーム
ユーザー 👑 NachiaNachia
提出日時 2020-09-27 12:27:44
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 20 ms / 5,000 ms
コード長 723 bytes
コンパイル時間 2,077 ms
コンパイル使用メモリ 166,520 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-09 04:59:34
合計ジャッジ時間 2,521 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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

int N;
bool sieve[10001] = {};
vector<int> P;
bool dp[10001] = {};

int main() {
    cin >> N;

    sieve[0] = sieve[1] = true;
    for (int i = 2; i < 1000; i++) {
        if (sieve[i]) continue;
        for (int j = i * i; j <= 10000; j += i) sieve[j] = true;
    }

    rep(i, 10001) if (!sieve[i]) P.push_back(i);

    dp[0] = dp[1] = true;
    for (int i = 2; i <= N; i++) {
        dp[i] = false;
        for (int p : P) {
            if (p > i) break;
            if (!dp[i - p]) dp[i] =  true;
        }
    }

    cout << (dp[N] ? "Win" : "Lose") << endl;

    return 0;
}
0