結果

問題 No.7 プライムナンバーゲーム
ユーザー MitI_7MitI_7
提出日時 2016-03-05 21:21:01
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,566 bytes
コンパイル時間 1,008 ms
コンパイル使用メモリ 90,344 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-24 19:58:54
合計ジャッジ時間 2,168 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <numeric>
#include <functional>
#include <set>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cctype>
#include <climits>
#include <fstream>
#include <bitset>
#include <time.h>

#define ll long long
#define FOR(i,a,b) for(int i= (a); i<((int)b); ++i)
#define RFOR(i,a) for(int i=(a); i >= 0; --i)
#define FOE(i,a) for(auto i : a)
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define EPS 1e-14

using namespace std;


// nまでの素数のリストを作成(nを含む)
vector<long long> getPrimeList(int n) {
    vector<bool> dp(n + 1, false);
    dp[0] = dp[1] = true;
    vector<long long> primeList;
    for (int i = 2; i < n + 1; ++i) {
        if (dp[i]) { continue; }
        primeList.push_back(i);
        for (int j = i; j < n + 1; j += i) {
            dp[j] = true;
        }
    }
    return primeList;
}


bool win(int n, const vector<ll> &primes) {
    if (n == 0 || n == 1) {
        return false;
    }

    FOE(p, primes) {
        if (p >= n) {
            if (!win(n - p, primes)) {
                return true;
            }
        }
    }
    return false;
}

int main(int argc, char *argv[]) {
    int N;
    cin >> N;
    vector<ll> p = getPrimeList(N);
    cout << (win(N, p) ? "Win" : "Lose") << endl;

    return 0;
}
0