結果

問題 No.7 プライムナンバーゲーム
ユーザー fantasiabaeticafantasiabaetica
提出日時 2018-07-02 16:52:47
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 753 bytes
コンパイル時間 505 ms
コンパイル使用メモリ 64,416 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-09-13 16:56:22
合計ジャッジ時間 30,592 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 TLE -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 TLE -
testcase_15 WA -
testcase_16 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string.h>

using namespace std;

bool is_prime(int n){
    for(int i = 2; i < n/2; i++) {
        if (n % i == 0) return 0;
    }
    return 1;
}

int main(){
    int N;
    cin >> N;
    // 渡って来たら負ける...0 渡って来たら勝てる...1
    int dp[10001];
    memset(dp, 0, sizeof(dp));
    // 2 ≤ i ≤ nのiについて、それ以下の素数jを引いた時に、dp[i-j]が0となるjがあれば1。そうでなければ0。
    for(int i = 2; i <= N; i++){
        for(int j = i - 2; j >= 2; j--){
            if (!(is_prime(j))) continue;
            if (dp[i - j] == 0){
                dp[i] = 1;
                break;
            }
        }
    }

    cout << dp[N] << endl;

    return 0;
}
0