結果

問題 No.7 プライムナンバーゲーム
ユーザー dazydazy
提出日時 2017-11-27 14:03:01
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 207 ms / 5,000 ms
コード長 1,070 bytes
コンパイル時間 644 ms
コンパイル使用メモリ 65,876 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-09 04:23:46
合計ジャッジ時間 2,669 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 207 ms
6,944 KB
testcase_03 AC 15 ms
6,948 KB
testcase_04 AC 5 ms
6,944 KB
testcase_05 AC 5 ms
6,944 KB
testcase_06 AC 60 ms
6,944 KB
testcase_07 AC 41 ms
6,944 KB
testcase_08 AC 19 ms
6,948 KB
testcase_09 AC 90 ms
6,944 KB
testcase_10 AC 1 ms
6,948 KB
testcase_11 AC 41 ms
6,948 KB
testcase_12 AC 146 ms
6,944 KB
testcase_13 AC 156 ms
6,944 KB
testcase_14 AC 205 ms
6,944 KB
testcase_15 AC 194 ms
6,944 KB
testcase_16 AC 179 ms
6,948 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];
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;
}

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;
        rep(j, 2, i+1) {
            if (prime[j]) {
                int next = i - j;
                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