結果

問題 No.7 プライムナンバーゲーム
ユーザー mencottonmencotton
提出日時 2020-02-12 18:59:47
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 7 ms / 5,000 ms
コード長 792 bytes
コンパイル時間 823 ms
コンパイル使用メモリ 75,040 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-09 04:49:11
合計ジャッジ時間 1,687 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <queue>

using namespace std;
const int INF = 1145141919;

int main() {
    vector<bool> isPrime(10010, true);
    vector<int> prime;
    isPrime[0] = false, isPrime[1] = false;
    for (int i = 2; i <= 10000; i++) {
        if (isPrime[i]) {
            prime.push_back(i);
            for (int j = i * i; j <= 10000; j += i)isPrime[j] = false;
        }
    }

    vector<bool> dp(10010, true);
    for (int i = 2; i <= 10000; i++) {
        bool found = false;
        for (auto x:prime) {
            if (x > i)break;
            if (!dp[i - x]) {
                found = true;
                break;
            }
        }
        dp[i] = found;
    }

    int n;
    cin >> n;
    cout << (dp[n] ? "Win" : "Lose") << endl;
    return 0;
}
0