結果

問題 No.7 プライムナンバーゲーム
ユーザー arrowsarrows
提出日時 2016-06-02 03:25:48
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 18 ms / 5,000 ms
コード長 808 bytes
コンパイル時間 2,097 ms
コンパイル使用メモリ 166,812 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-09 04:00:37
合計ジャッジ時間 2,596 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#define MAX 10010

vector<int> make_prime()
{
    vector<int> pv;
    bool prime[MAX];
    fill(prime, prime + MAX, 1);
    prime[0] = prime[1] = 0;
    for (int i = 2; i < MAX; i++) {
        if (prime[i]) {
            pv.push_back(i);
            for (int j = i * 2; j < MAX; j += i) {
                prime[j] = 0;
            }
        }
    }
    return pv;
}

bool solve(int N)
{
    vector<int> prime = make_prime();
    bool dp[MAX] = {};
    dp[0] = dp[1] = 1;    
    for (int i = 2; i <= N; i++) {
        for (int j: prime) {
            if (i - j >= 0) {
                dp[i] |= !dp[i - j];
            }
        }
    }
    return dp[N];
}

int main()
{
    int N;
    cin >> N;
    cout << (solve(N) ? "Win" : "Lose") << endl;
    return 0;
}
0