結果

問題 No.7 プライムナンバーゲーム
ユーザー youse_8zlyouse_8zl
提出日時 2017-12-30 11:54:24
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 850 bytes
コンパイル時間 1,498 ms
コンパイル使用メモリ 166,992 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-23 10:59:56
合計ジャッジ時間 2,420 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 WA -
testcase_02 AC 6 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 WA -
testcase_06 AC 3 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 WA -
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 3 ms
4,376 KB
testcase_12 AC 5 ms
4,380 KB
testcase_13 AC 5 ms
4,376 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 5 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define INF 1e+9
#define MOD (int)1e9+7
#define debug(x) cerr << #x << ": " << x << "\n";
using namespace std;
using ll = long long;
using P = pair<int, int>;

vector<int> prime;
bool win[10001];

int main(void){
    int N; cin >> N;
    prime.push_back(2);
    for(int i = 3; i <= N; i++){
        for(auto p: prime){
            if(i % p == 0) break;
            else if(p == *(end(prime) - 1)) prime.push_back(i);
        }
    }

    win[0] = win[1] = 1;
    for(int i = 2; i <= N; i++){
        win[i] = 0;
        for(int j = 0; prime[j] <= i; j++){
            if(win[i - prime[j]] == 0){
                win[i] = 1;
                break;
            }
        }
        // debug(i);debug(win[i]);
    }

    // for(auto p: prime) debug(p);

    if(win[N]) cout << "Win\n";
    else cout << "Lose\n";

    return 0;
}
0