結果

問題 No.7 プライムナンバーゲーム
ユーザー kokatsukokatsu
提出日時 2022-10-16 21:50:30
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 4 ms / 5,000 ms
コード長 658 bytes
コンパイル時間 1,909 ms
コンパイル使用メモリ 202,556 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-09-04 18:34:15
合計ジャッジ時間 3,091 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

import std;

void main() {
    int N;
    readf("%d\n", N);

    auto sieve = new bool[](N+1);
    sieve[2..N+1] = true;
    int d = 2;
    while (d * d <= N) {
        if (sieve[d]) {
            foreach (i; iota(d*d, N+1, d)) {
                sieve[i] = false;
            }
        }
        ++d;
    }

    auto primes = iota(N+1).filter!(i => sieve[i]).array;

    auto dp = new bool[](N+1);
    dp[0..2] = true;
    foreach (i; 2 .. N+1) {
        foreach (p; primes) {
            if (i < p) break;

            if (!dp[i-p]) {
                dp[i] = true;
                break;
            }
        }
    }

    writeln(dp[N] ? "Win" : "Lose");
}
0