結果

問題 No.7 プライムナンバーゲーム
ユーザー sawfishsawfish
提出日時 2022-10-17 05:36:52
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 4 ms / 5,000 ms
コード長 849 bytes
コンパイル時間 826 ms
コンパイル使用メモリ 73,460 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-10 06:28:33
合計ジャッジ時間 1,578 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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

using namespace std;
using LL = long long;

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

    //
    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 + i; j <= N; j += i) {
                P_[j] = false;
            }
        }
    }

    vector<int> P;
    for (int i = 2; i <= N; i++) {
        if (P_[i]) 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) break;
            if (!WL[i - p]) {
                WL[i] = true;
                break;
            }
        }
    }

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