結果

問題 No.7 プライムナンバーゲーム
ユーザー tadanoningentadanoningen
提出日時 2020-09-23 07:12:22
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 405 ms / 5,000 ms
コード長 933 bytes
コンパイル時間 2,103 ms
コンパイル使用メモリ 74,908 KB
実行使用メモリ 22,968 KB
最終ジャッジ日時 2023-07-24 21:41:08
合計ジャッジ時間 4,119 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 405 ms
22,968 KB
testcase_03 AC 21 ms
4,716 KB
testcase_04 AC 6 ms
4,380 KB
testcase_05 AC 6 ms
4,380 KB
testcase_06 AC 103 ms
9,256 KB
testcase_07 AC 66 ms
7,192 KB
testcase_08 AC 29 ms
5,216 KB
testcase_09 AC 164 ms
12,080 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 68 ms
7,568 KB
testcase_12 AC 277 ms
16,300 KB
testcase_13 AC 297 ms
17,440 KB
testcase_14 AC 402 ms
22,940 KB
testcase_15 AC 379 ms
21,800 KB
testcase_16 AC 348 ms
20,132 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<algorithm>
#define ll long long

using namespace std;


vector<int> prime(int n){
    vector<bool> is_prime(n+1,true);
    vector<int> p;
    for(int i=2;i <= n;i++){
        if(is_prime[i]){
            for(int j=2*i;j <= n;j+=i){
                is_prime[j] = false;
            }
            p.push_back(i);
        }
    }
    return p;
}

vector<bool> dp(10010,false);
vector<bool> calced(10010,false);

bool dfs(int n){


    if(n == 0 || n == 1){
        return dp[n] = true;
    } 
    if(n == 2 || n == 3) {
        return dp[n] = false;
    }
    if(calced[n]) return dp[n];

    calced[n] = true;
    
    bool res = false;
    for(auto &x : prime(n)){
        if(!dfs(n-x)){
            return dp[n] = true;
        }
    }
    return dp[n] = false;
}

int main(){
    int n;
    cin >> n;
    if(dfs(n)) cout << "Win" << endl;
    else cout << "Lose" << endl;
    return 0;
}
0