結果

問題 No.7 プライムナンバーゲーム
ユーザー dazydazy
提出日時 2017-11-27 13:56:12
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 118 ms / 5,000 ms
コード長 1,125 bytes
コンパイル時間 714 ms
コンパイル使用メモリ 67,212 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-07-24 21:01:51
合計ジャッジ時間 2,050 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,384 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 102 ms
4,376 KB
testcase_03 AC 9 ms
4,384 KB
testcase_04 AC 3 ms
4,380 KB
testcase_05 AC 4 ms
4,376 KB
testcase_06 AC 37 ms
4,380 KB
testcase_07 AC 22 ms
4,380 KB
testcase_08 AC 11 ms
4,376 KB
testcase_09 AC 48 ms
4,376 KB
testcase_10 AC 1 ms
4,384 KB
testcase_11 AC 25 ms
4,380 KB
testcase_12 AC 85 ms
4,380 KB
testcase_13 AC 91 ms
4,380 KB
testcase_14 AC 118 ms
4,376 KB
testcase_15 AC 100 ms
4,384 KB
testcase_16 AC 99 ms
4,376 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