結果

問題 No.7 プライムナンバーゲーム
ユーザー dazydazy
提出日時 2017-11-27 13:56:12
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 125 ms / 5,000 ms
コード長 1,125 bytes
コンパイル時間 526 ms
コンパイル使用メモリ 67,928 KB
実行使用メモリ 6,692 KB
最終ジャッジ日時 2024-04-09 04:23:37
合計ジャッジ時間 2,120 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,564 KB
testcase_01 AC 1 ms
6,692 KB
testcase_02 AC 125 ms
6,692 KB
testcase_03 AC 11 ms
6,692 KB
testcase_04 AC 4 ms
6,688 KB
testcase_05 AC 4 ms
6,692 KB
testcase_06 AC 39 ms
6,688 KB
testcase_07 AC 27 ms
6,692 KB
testcase_08 AC 14 ms
6,692 KB
testcase_09 AC 58 ms
6,692 KB
testcase_10 AC 1 ms
6,688 KB
testcase_11 AC 27 ms
6,692 KB
testcase_12 AC 91 ms
6,688 KB
testcase_13 AC 97 ms
6,688 KB
testcase_14 AC 125 ms
6,688 KB
testcase_15 AC 118 ms
6,688 KB
testcase_16 AC 110 ms
6,692 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <set>

using namespace std;

#define fastcin {\
    cin.tie(0);\
    ios::sync_with_stdio(false);\
}
#define rep(i, a, b) for(int i = a; i < b; i++)
#define REP(i, a) for(int i = 0; i < a; i++)
#define scan(x) cin >> x
#define print(x) cout << x << "\n"

bool prime[10001];
vector<int> primelist;
int gr[10001];

void makePrimeList (int x) {
    REP(i, x+1) prime[i] = true;
    prime[0] = prime[1] = false;
    rep(i, 2, x+1) {
        if (prime[i]) {
            for (int j = i << 1; j < x+1; j += i) prime[j] = false;
            primelist.push_back(i);
        }
    }
}

int main() {
    fastcin;

    int n; scan(n);

    makePrimeList(n);

    gr[0] = gr[1] = gr[2] = gr[3] = 0;
    rep(i, 4, n+1) {
        set<int> g;
        for (auto &v: primelist) {
            int next = i - v;
            if (next < 2) break;
            g.insert(gr[next]);
        }
        int res = 0;
        for (auto &s: g) {
            if (res == s) res++;
            else break;
        }
        gr[i] = res;
    }
    if (gr[n]) print("Win");
    else print("Lose");

    return 0;
}
0