結果

問題 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,584 ms
コンパイル使用メモリ 65,576 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-07-24 21:20:43
合計ジャッジ時間 2,503 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 23 ms
4,380 KB
testcase_03 AC 3 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 8 ms
4,376 KB
testcase_07 AC 5 ms
4,384 KB
testcase_08 AC 3 ms
4,380 KB
testcase_09 AC 11 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 6 ms
4,376 KB
testcase_12 AC 17 ms
4,380 KB
testcase_13 AC 18 ms
4,384 KB
testcase_14 AC 23 ms
4,380 KB
testcase_15 AC 22 ms
4,380 KB
testcase_16 AC 20 ms
4,376 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