結果

問題 No.7 プライムナンバーゲーム
ユーザー kawacchukawacchu
提出日時 2019-11-13 10:09:20
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 50 ms / 5,000 ms
コード長 788 bytes
コンパイル時間 2,357 ms
コンパイル使用メモリ 198,632 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-09 04:45:01
合計ジャッジ時間 3,209 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    int n; cin >> n;
    vector<bool> is_prime(n+1, true);
    vector<bool> can_win(n+1, false);

    is_prime[0] = false;
    is_prime[1] = false;
    for (int i = 2; i < int(pow(n, 0.5))+1; i++) {
        if (is_prime[i]) {
            int j = i + i;
            while (j <= n) {
                is_prime[j] = false;
                j += i;
            }
        }
    }
    for (int i = 2; i < n+1; i++) {
        for (int j = 2; j < n+1; j++) {
            if (i-j >= 2 && is_prime[j] && !can_win[i-j]) {
                can_win[i] = true;
                break;
            }
        }
    }
    string res = (can_win[n]) ? "Win" : "Lose";
    cout << res << endl;
}
0