結果

問題 No.7 プライムナンバーゲーム
ユーザー kuisibakuisiba
提出日時 2016-04-18 23:57:34
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,147 bytes
コンパイル時間 703 ms
コンパイル使用メモリ 61,660 KB
実行使用メモリ 237,824 KB
最終ジャッジ日時 2024-04-15 03:41:14
合計ジャッジ時間 3,690 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 WA -
testcase_02 AC 320 ms
237,824 KB
testcase_03 AC 20 ms
16,000 KB
testcase_04 AC 6 ms
6,940 KB
testcase_05 WA -
testcase_06 AC 87 ms
66,816 KB
testcase_07 AC 56 ms
44,544 KB
testcase_08 AC 25 ms
20,864 KB
testcase_09 WA -
testcase_10 AC 1 ms
6,944 KB
testcase_11 AC 56 ms
45,184 KB
testcase_12 AC 210 ms
165,504 KB
testcase_13 AC 226 ms
177,408 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 269 ms
205,696 KB
権限があれば一括ダウンロードができます

ソースコード

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