結果

問題 No.7 プライムナンバーゲーム
ユーザー _oba23__oba23_
提出日時 2018-08-21 21:23:55
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 36 ms / 5,000 ms
コード長 614 bytes
コンパイル時間 583 ms
コンパイル使用メモリ 63,788 KB
実行使用メモリ 6,696 KB
最終ジャッジ日時 2024-04-09 04:31:28
合計ジャッジ時間 1,659 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>

using namespace std;

int main(){
    int n;
    cin >> n;
    vector<int> primes;
    vector<bool> cache(n+1, false);
    cache[0]=cache[1]=true;

    for(int i=2; i<=n; ++i){
        bool is_prime=true;
        for(auto prime : primes){
            if(i%prime==0){
                is_prime=false;
                break;
            }
        }
        if(is_prime){
            primes.push_back(i);
        }
        for(auto prime : primes){
            cache[i]=cache[i] | !cache[i-prime];
        }
    }
    cout << (cache[n] ? "Win" : "Lose") << endl;
    return 0;
}
0