結果

問題 No.7 プライムナンバーゲーム
ユーザー zn_kiezn_kie
提出日時 2019-07-10 22:49:03
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 23 ms / 5,000 ms
コード長 991 bytes
コンパイル時間 1,562 ms
コンパイル使用メモリ 65,056 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-09 04:40:02
合計ジャッジ時間 2,843 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); ++i)

int main(){
    int N;
    cin >> N;
    // N以下の素数を求める
    vector<int> p_num;
    p_num.push_back(2);
    for(int i=3;i<=N;i++){
        bool flg = true;
        for(int j=0;j<p_num.size();j++){
            if(i%p_num[j]==0) flg = false;
        }
        if(flg) p_num.push_back(i);
    }
    
    // 下から順にたどっていって、過去の結果を利用していく
    // A[i]がwinなら1,Loseならとすると
    // LoseになるAに対して素数を足したものはすべてWinになる
    vector<int> A(N+1);
    for(int i=2;i<=N;i++){
        if(A[i] == 1) continue;
        for(int j=0;j<p_num.size();j++){
            if(i+p_num[j]<=N){
                A[i + p_num[j]] = 1;
            }
        }
    }
    
    if(A[N]) cout << "Win" << endl;
    else cout << "Lose" << endl;
    return 0;
}
0