結果

問題 No.7 プライムナンバーゲーム
ユーザー mamekinmamekin
提出日時 2015-01-11 14:38:47
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 133 ms / 5,000 ms
コード長 1,069 bytes
コンパイル時間 996 ms
コンパイル使用メモリ 96,864 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-09 03:41:21
合計ジャッジ時間 2,618 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
using namespace std;

void findPrime(int N, vector<bool>& isPrime)
{
    isPrime.assign(N+1, true);
    isPrime[0] = isPrime[1] = false;
    for(int i=2; i*i<=N; i++){
        if(isPrime[i]){
            for(int j=i; i*j<=N; j++){
                isPrime[i*j] = false;
            }
        }
    }
}

int main()
{
    int n;
    cin >> n;
    vector<bool> isPrime;
    findPrime(n, isPrime);

    vector<bool> dp(n+1, false);
    dp[0] = dp[1] = false;
    for(int i=2; i<=n; ++i){
        for(int j=2; j<=i-2; ++j){
            if(isPrime[j] && !dp[i-j])
                dp[i] = true;
        }
    }

    if(dp[n])
        cout << "Win" << endl;
    else
        cout << "Lose" << endl;

    return 0;
}
0