結果

問題 No.7 プライムナンバーゲーム
ユーザー sawfishsawfish
提出日時 2022-10-17 05:25:12
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 773 bytes
コンパイル時間 615 ms
コンパイル使用メモリ 73,568 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-10 06:19:14
合計ジャッジ時間 1,945 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <cmath>
#include <vector>

using namespace std;
using LL = long long;

int main() {
    int N;
    cin >> N;

    vector<int> P;
    bool P_[N + 1];
    for (bool &i: P_) i = true;
    P_[0] = P_[1] = false;
    for (int i = 2; i <= sqrt(N); i++) {
        if (P_[i]) {
            for (int j = i * 2; j <= N; j += i) {
                P_[j] = false;
            }
            P.push_back(i);
        }
    }

    //
    bool WL[N + 2];
    WL[0] = WL[1] = true;
    WL[2] = WL[3] = false;
    for (int i = 4; i <= N; i++) {
        WL[i] = false;
        for (int p: P) {
            if (p <= i && !WL[i - p]) {
                WL[i] = true;
                break;
            }
        }
    }

    cout << (WL[N] ? "Win" : "Lose") << endl;
}
0