結果

問題 No.7 プライムナンバーゲーム
ユーザー IlagIlag
提出日時 2020-06-15 21:02:01
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 8 ms / 5,000 ms
コード長 890 bytes
コンパイル時間 1,605 ms
コンパイル使用メモリ 163,404 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-09 04:55:00
合計ジャッジ時間 2,444 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;

const int MAX_N = 11111;

int prime[MAX_N];
bool is_prime[MAX_N + 1];

int sieve(int n) {
    int p = 0;
    for (int i = 0; i <= n; i++) is_prime[i] = true;
    is_prime[0] = is_prime[1] = false;
    for (int i = 2; i <= n; i++) {
        if (is_prime[i]) {
            prime[p++] = i;
            for (int j = 2 * i; j <= n; j += i) is_prime[j] = false;
        }
    }
    return p;
}

bool lose[MAX_N];

int main() {
    int n;
    cin >> n;
    int p = sieve(n);
    lose[0] = lose[1] = true;
    for (int i = 2; i <= n; i++) {
        bool flag = false;
        for (int j = 0; j < p; j++) {
            if (i - prime[j] <= 1) break;
            flag |= lose[i - prime[j]];
        }
        lose[i] = !flag;
    }
    if (lose[n]) cout << "Lose" << endl;
    else cout << "Win" << endl;
}
0