結果

問題 No.7 プライムナンバーゲーム
ユーザー Im_GimletIm_Gimlet
提出日時 2020-07-23 00:33:29
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 137 ms / 5,000 ms
コード長 1,336 bytes
コンパイル時間 2,289 ms
コンパイル使用メモリ 167,552 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-09 04:57:33
合計ジャッジ時間 3,457 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 137 ms
6,948 KB
testcase_03 AC 9 ms
6,944 KB
testcase_04 AC 4 ms
6,944 KB
testcase_05 AC 4 ms
6,944 KB
testcase_06 AC 39 ms
6,944 KB
testcase_07 AC 26 ms
6,944 KB
testcase_08 AC 12 ms
6,944 KB
testcase_09 AC 58 ms
6,944 KB
testcase_10 AC 2 ms
6,944 KB
testcase_11 AC 27 ms
6,944 KB
testcase_12 AC 94 ms
6,948 KB
testcase_13 AC 104 ms
6,944 KB
testcase_14 AC 136 ms
6,944 KB
testcase_15 AC 129 ms
6,948 KB
testcase_16 AC 117 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using ll = long long;
using P = pair<ll, ll>;
const long double PI = acos(-1.0L);
ll GCD(ll a, ll b) { return b?GCD(b, a%b):a; }
ll LCM(ll a, ll b) { return a/GCD(a, b)*b; }

// Eratosthenesの篩
vector<bool> primeno(100010, true);
void Eratosthenes(int n) {
    primeno.at(0) = primeno.at(1) = false;
    int limit = sqrt(n);
    for(int i = 2; i < limit; ++i) {
        if(primeno.at(i)) {
            for(int j = 0; i*(j+2) < n; ++j) {
                primeno.at(i*(j+2)) = false;
            }
        }
    }
}

int n;
int dp[10010];

int main() {
    cin >> n;
    Eratosthenes(10010);
    for(int i = 0; i <= n; ++i) dp[i] = -1;
    // 0のとき負ける
    dp[0] = dp[1] = 1; dp[2] = dp[3] = 0;
    for(int i = 4; i <= n; ++i) {
        for(int j = 2; j <= i; ++j) {
            if(primeno[j]) {
                if(dp[i-j] == 0) {
                    // 相手に負けの手を渡せる
                    dp[i] = 1;
                }
            }
        }
        if(dp[i] == -1) dp[i] = 0;
    }

    if(dp[n] == 0) cout << "Lose" << endl;
    else cout << "Win" << endl;
}
0