結果

問題 No.7 プライムナンバーゲーム
ユーザー trineutrontrineutron
提出日時 2019-05-10 15:42:12
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 44 ms / 5,000 ms
コード長 978 bytes
コンパイル時間 1,564 ms
コンパイル使用メモリ 165,052 KB
実行使用メモリ 6,952 KB
最終ジャッジ日時 2024-04-09 04:38:05
合計ジャッジ時間 2,817 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,816 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 44 ms
6,944 KB
testcase_03 AC 3 ms
6,948 KB
testcase_04 AC 2 ms
6,948 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 12 ms
6,944 KB
testcase_07 AC 7 ms
6,948 KB
testcase_08 AC 4 ms
6,948 KB
testcase_09 AC 19 ms
6,948 KB
testcase_10 AC 1 ms
6,944 KB
testcase_11 AC 8 ms
6,948 KB
testcase_12 AC 30 ms
6,944 KB
testcase_13 AC 33 ms
6,944 KB
testcase_14 AC 44 ms
6,944 KB
testcase_15 AC 42 ms
6,952 KB
testcase_16 AC 38 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main()
{
    const vector<int> primes_div = {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97};
    int n; cin >> n;
    vector<int> primes(n+1);
    for (int i = 2; i <= n; i++) {
        primes.at(i) = i;
        for (int j = 0; j < 25; j++) {
            if (i <= primes_div.at(j)) break;
            if (i % primes_div.at(j) == 0) {
                primes.at(i) = 0;
                break;
            }
        }
    }
    vector<bool> iswin(n+1);
    iswin.at(0) = true; iswin.at(1) = true;
    for (int i = 2; i <= n; i++) {
        for (int j = 0; j <= n; j++) {
            if (primes.at(j) == 0) continue;
            if (primes.at(j) > i) break;
            if (iswin.at(i-primes.at(j)) == false) {
                iswin.at(i) = true;
                break;
            }
        }
    }
    if (iswin.at(n)) {
        cout << "Win" << endl;
    } else {
        cout << "Lose" << endl;
    }
}
0