結果

問題 No.7 プライムナンバーゲーム
ユーザー maine_honzukimaine_honzuki
提出日時 2020-05-03 14:29:21
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 5 ms / 5,000 ms
コード長 680 bytes
コンパイル時間 1,727 ms
コンパイル使用メモリ 166,224 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-09 04:53:06
合計ジャッジ時間 2,591 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

bool is_prime(int n) {
    for (int i = 2; i * i <= n; i++)
        if (n % i == 0) return false;
    return true;
}

int memo[10010];

vector<int> V;
int f(int x) {
    if (memo[x] != -1)
        return memo[x];
    for (int i = 0; i < V.size() && V[i] <= x; i++) {
        if (f(x - V[i]) == 0)
            return memo[x] = 1;
    }
    return memo[x] = 0;
}

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

    for (int i = 2; i <= N; i++) {
        if (is_prime(i))
            V.push_back(i);
    }

    for (int i = 0; i <= N; i++)
        memo[i] = -1;
    memo[0] = 1;
    memo[1] = 1;

    cout << (f(N) ? "Win" : "Lose") << endl;
}
0