結果

問題 No.7 プライムナンバーゲーム
ユーザー ermineermine
提出日時 2023-01-26 22:16:10
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 20 ms / 5,000 ms
コード長 616 bytes
コンパイル時間 2,016 ms
コンパイル使用メモリ 200,472 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-09 20:35:53
合計ジャッジ時間 3,154 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

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


int main() {
    int n;
    cin>>n;
    vector<int> p(n+1,1);
    p[0]=p[1]=0;

    for(int i=2; i*i<=n; i++){
        for(int j=i*2; j<=n; j+=i){
            p[j]=0;
        }
    }

    vector<int> pm;
    for(int i=2; i<=n; i++){
        if(p[i]) pm.push_back(i);
    }

    vector<int> win(n+1,0);
    win[0]=win[1]=1;
    for(int i=2; i<=n; i++){
        int k=i;

        for(int x:pm){
            if(x>=k) break;
            if(!win[k-x]){
                win[i]=1;
            }
        }
    }

    cout << (win[n] ? "Win" : "Lose") << endl;
    return 0;
}
0