結果

問題 No.7 プライムナンバーゲーム
ユーザー vintersn0wvintersn0w
提出日時 2018-05-13 00:20:18
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 979 bytes
コンパイル時間 638 ms
コンパイル使用メモリ 76,284 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-10 18:35:32
合計ジャッジ時間 3,728 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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[1001] = {};
    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