結果

問題 No.7 プライムナンバーゲーム
ユーザー yogi_cgyogi_cg
提出日時 2020-03-27 18:41:34
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 5 ms / 5,000 ms
コード長 1,452 bytes
コンパイル時間 1,751 ms
コンパイル使用メモリ 169,660 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-09 04:51:06
合計ジャッジ時間 2,321 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h> 

#define int long long

#define REP(i, b) for(int i = 0; i < (b); i++)
#define REPS(i, b) for(int i = 1; i <= (b); i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;

using pi = pair<int, int>;
using vi = vector<int>;
using vs = vector<string>;
using vb = vector<bool>;
using vpi = vector<pi>;
using vvi = vector<vi>;
using vvb = vector<vb>;

const int INF = 1e10;
const int MOD = 1e9+7;

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; }

signed main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    int N; cin >> N;
    vb prime(10001, true); prime[0] = prime[1] = false;
    for(int i = 2; i * i <= 10000; i++)
    {
        if(prime[i])
        {
            for(int j = 2*i; j <= 10000; j += i) prime[j] = false;
        }
    }
    vi primetable;
    REP(i, 10001) if(prime[i]) primetable.push_back(i);

    vb win(10001, false); win[0] = win[1] = true;
    for(int i = 4; i <= N; i++)
    {
        REP(j, primetable.size())
        {
            if(i - primetable[j] < 0) break;
            if(win[i-primetable[j]] == false)
            {
                win[i] = true;
                break;
            }
        }
    }
    if(win[N]) cout << "Win" << endl;
    else cout << "Lose" << endl;
}
0