結果

問題 No.7 プライムナンバーゲーム
ユーザー rgnerdplayerrgnerdplayer
提出日時 2024-02-14 02:35:32
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 13 ms / 5,000 ms
コード長 950 bytes
コンパイル時間 2,973 ms
コンパイル使用メモリ 247,992 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-02-14 02:35:36
合計ジャッジ時間 4,170 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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

using i64 = long long;

int main() {
    cin.tie(nullptr)->sync_with_stdio(false);

    auto solve = [&]() {
        int n;
        cin >> n;

        auto isPrime = [&](int n) {
            if (n == 1) { return false; }
            for (int i = 2; i * i <= n; i++) {
                if (n % i == 0) {
                    return false;
                }
            }
            return true;
        };

        vector<int> primes;
        for (int x = 1; x <= n; x++) {
            if (isPrime(x)) {
                primes.push_back(x);
            }
        }

        vector<int> dp(n);
        for (int i = 2; i <= n; i++) {
            for (auto p : primes) {
                if (i - p <= 1) {
                    break;
                }
                dp[i] |= !dp[i - p];
            }
        }

        cout << (dp[n] ? "Win" : "Lose") << '\n';
    };
    
    solve();
    
    return 0;
}
0