結果

問題 No.7 プライムナンバーゲーム
ユーザー vintersn0wvintersn0w
提出日時 2018-05-13 00:21:18
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 24 ms / 5,000 ms
コード長 980 bytes
コンパイル時間 778 ms
コンパイル使用メモリ 77,892 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-09 04:28:26
合計ジャッジ時間 1,647 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>
#include <stdio.h>
#include <cmath>
#include <vector>

using namespace std;
typedef uint uint32_t;

bool isPrime(int n) {
    if (n <= 1) return false;
    if (n == 2) return true;
    if (n % 2 == 0) return false;

    for (int i = 3; i <= sqrt(n); i+=2) {
        if (n % i == 0) return false;
    }

    return true;
}

bool check(int N) {
    int dp[10001] = {};
    vector<int> prime;

    // if (N == 2 || N == 3) return true;

    dp[0] = dp[1] = 2;  // 1は負け, 2なら勝ち
    dp[2] = dp[3] = 1;
    prime.push_back(2);
    prime.push_back(3);

    for (int i = 4; i <= N; i++) {
        dp[i] = 1;
        for (int p : prime) {
            if (dp[i - p] == 1) {
                dp[i] = 2;
            }
        }
        if (isPrime(i)) prime.push_back(i);
    }

    return dp[N] == 2;
}


int main() {
    int N;
    cin >> N;

    if (check(N)) cout << "Win" << endl;
    else cout << "Lose" << endl;
}
0