結果

問題 No.7 プライムナンバーゲーム
ユーザー tktk_snsntktk_snsn
提出日時 2021-01-18 22:27:34
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 8 ms / 5,000 ms
コード長 1,027 bytes
コンパイル時間 1,675 ms
コンパイル使用メモリ 167,808 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-09 05:02:17
合計ジャッジ時間 2,535 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(n); i++)
using namespace std;
template<class T> inline bool chmax(T& a, T b){ if (a < b){ a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b){ if (a > b){ a = b; return true; } return false; }


vector<int> prime_sieve(int n){
    vector<int> sieve(n+1, 0), prime;
    for (int i=2; i<n+1; i++){
        if (sieve[i]==0){
            sieve[i] = i;
            prime.emplace_back(i);
        }
        for (int p: prime){
            if (p > sieve[i] || i * p > n) break;
            sieve[i * p] = p;
        }
    }
    return sieve;
}


bool dp[10101];

int main(){
    int n; cin>>n;
    dp[0] = true;
    dp[1] = true;
    vector<int> sieve = prime_sieve(n);
    vector<int> p;

    for (int x = 2; x<=n; x++){
        if (x == sieve[x]) p.push_back(x);
        bool win = false;
        for(int i: p) if(!dp[x-i]) win=true;
        dp[x] = win;
    }
    if (dp[n]) cout<<"Win"<<endl;
    else cout<<"Lose"<<endl;
    return 0;
}
0