結果

問題 No.7 プライムナンバーゲーム
ユーザー NacoNaco
提出日時 2019-07-12 00:52:15
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 13 ms / 5,000 ms
コード長 1,452 bytes
コンパイル時間 818 ms
コンパイル使用メモリ 75,696 KB
実行使用メモリ 6,696 KB
最終ジャッジ日時 2024-04-09 04:40:13
合計ジャッジ時間 1,631 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<iostream>
#include<vector>
#include<map>
using namespace std;
typedef long long ll;

map<ll,ll> prime_factor(ll n){ //素因数分解
    map<ll,ll> table;
    for(int i=2;i*i<=n;i++){
        while(n%i==0){
            table[i]++;
            n/=i;
        }
    }
    if(n!=1) table[n]=1;
    return table;// key->素因数, value->べき乗
}

bool is_prime(int n){ //素数判定
    for(int i=2;i*i<=n;i++){
        if(n%i==0) return true;
    }
    return false;
}

vector<bool> prime_table(int n){ //素数全列挙
    vector<bool> prime(n+1,true);
    prime[0]=prime[1]=false;
    for(int i=2;i*i<=n;i++){
        if(prime[i]!=true) continue;
        for(int j=2*i;j<=n;j+=i){
            prime[j]=false;
        }
    }
    return prime; //i番目の要素が素数の場合trueを返す
}

vector<int> p;


int main(){
    int N;
    cin >> N;
    vector<bool> p_table=prime_table(N);
    for(int i=2;i<=N;i++){
        if(p_table[i]==true){
            p.push_back(i);
        }
    }
    bool dp[N+1];
    for(int i=0;i<=N;i++) dp[i]=false;
    dp[0]=true;
    dp[1]=true;
    for(int i=2;i<=N;i++){
        for(int j=0;j<p.size();j++){
            if(dp[i]==true) continue; //勝つ選択肢が一つあればok
            if(i-p[j]>=0){
                if(!dp[i-p[j]]){
                    dp[i]=true;
                }
            }
        }
    }
    if(dp[N]==true) cout << "Win" << endl;
    else cout << "Lose" << endl;
}
0