結果

問題 No.7 プライムナンバーゲーム
ユーザー KuphonyKuphony
提出日時 2016-03-17 17:32:20
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 25 ms / 5,000 ms
コード長 1,065 bytes
コンパイル時間 500 ms
コンパイル使用メモリ 66,728 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-07-24 20:32:14
合計ジャッジ時間 1,432 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#define MAX 10000
using namespace std;

bool isPrime(int n){
    if(n == 1){
        return false;
    }
    if(n == 2){
        return true;
    }
    bool flag = true;
    for (int i = 2; i < n; i++) {
        if(n%i == 0){flag = false;break;}
    }
    return flag;
}

vector<int> returnPrimeList(int n){
    vector<int> a;
    if(n == 1){return a;}
    a.push_back(2);//2は先に追加しておく
    for (int i = 3; i <= n; i += 2) {
        //素数の場合追加
        if(isPrime(i)){a.push_back(i);}
    }
    return a;
}


int main(int argc, const char * argv[]) {
    int n;
    cin >> n;
    bool dp[MAX];
    vector<int> primes = returnPrimeList(n);
    for (int i = 0; i < MAX; i++) {
        dp[i] = false;
    }
    dp[0] = true;dp[1] = true;
    for (int i = 2; i <= n; i++) {
        for (int j: primes) {
            if(i-j < 0)break;
            dp[i] = (dp[i]| !dp[i-j]);
        }
    }
    if(dp[n])cout << "Win\n";
    else cout << "Lose\n";
}
0