結果

問題 No.7 プライムナンバーゲーム
ユーザー fantasiabaeticafantasiabaetica
提出日時 2018-07-02 16:54:13
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 802 bytes
コンパイル時間 478 ms
コンパイル使用メモリ 65,860 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-07-24 21:12:27
合計ジャッジ時間 33,671 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 TLE -
testcase_03 AC 90 ms
4,376 KB
testcase_04 AC 14 ms
4,380 KB
testcase_05 AC 13 ms
4,380 KB
testcase_06 AC 868 ms
4,376 KB
testcase_07 AC 480 ms
4,380 KB
testcase_08 AC 144 ms
4,376 KB
testcase_09 AC 1,645 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 485 ms
4,376 KB
testcase_12 AC 3,494 ms
4,380 KB
testcase_13 AC 3,856 ms
4,380 KB
testcase_14 TLE -
testcase_15 TLE -
testcase_16 AC 4,687 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

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;
            }
        }
    }

    if (dp[N] == 1) cout << "Win" << endl;
    else cout << "Lose" << endl;

    return 0;
}
0