結果

問題 No.7 プライムナンバーゲーム
ユーザー kuisiba
提出日時 2016-04-18 23:57:34
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 1,147 bytes
コンパイル時間 561 ms
コンパイル使用メモリ 61,784 KB
実行使用メモリ 237,824 KB
最終ジャッジ日時 2024-10-04 13:59:08
合計ジャッジ時間 3,155 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 12 WA * 5
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>

using namespace std;

//nまでの素数の表
vector<int> furui(int n) {
    vector<int> primeList;
    vector<int> allNum(n, 1); //素数なら1、違うなら0
    allNum.at(0) = 0;
    allNum.at(1) = 0;
    for (int i = 2; i * i <= n; ++i) {
        if(allNum.at(i) == 1) {
            for (int j = i + i; j < n; j += i) {
                allNum.at(j) = 0;
            }
        }
    }
    primeList.push_back(2);
    for (int i = 3; i < n; i +=2) {
        if(allNum.at(i)) {
            primeList.push_back(i);
        }
    }
    return primeList;
}

//自分から見てwinなら1、loseなら0を返す
int func(int n) {
    vector<int> primeList = furui(n);
    vector<int> worl(n + 1, -1);
    if (worl.at(n) != -1) return worl.at(n);
    for (auto i : primeList) {
        if (n - i < 2) break;
        if (func(n-1) != -1) {
            worl.at(n) = 1;
            return worl.at(n);
        }
    }
    return worl.at(n) = 0;
}

int main() {

    std::ios::sync_with_stdio(false);
    std::cin.tie(0);

    int n;
    cin >> n;
    cout<< (func(n) ? "Win" : "Lose") << endl;
    return 0;
}
0