結果

問題 No.7 プライムナンバーゲーム
ユーザー HentciHentci
提出日時 2022-03-29 15:35:25
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 6 ms / 5,000 ms
コード長 1,163 bytes
コンパイル時間 2,051 ms
コンパイル使用メモリ 199,744 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-09 05:07:12
合計ジャッジ時間 2,784 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(x) x.begin(),x.end()
#define ar array
#define sz(x) ((int)x.size())
template <class T,class S> inline bool chmin(T &a,const S &b) {return (a> b? a= b, 1: 0);}
template <class T,class S> inline bool chmax(T &a,const S &b) {return (a< b? a= b, 1: 0);}
int main(){
    ios_base::sync_with_stdio(false),cin.tie(0);
    int n;
    cin >> n;
    vector <bool> prime(n + 5, true);
    auto initPrime = [&]() -> void{
        for(ll i = 2;i * i <= n;i++){
            if(prime[i])
                for(int j = i * i;j <= n;j += i)
                    prime[j] = false;
        }
    };

    initPrime();

    vector <int> p;
    for(int i = 2;i <= n;i++)
        if(prime[i]) p.push_back(i);
    
    // for(auto ele: p) cout << ele << " ";
    // cout << "\n";

    vector <bool> dp(n + 1, false);
    dp[0] = 1, dp[1] = 1;
    for(int i = 2;i <= n;i++){
        for(auto ele: p){
            if(i - ele < 0) break;
            if(!dp[i - ele]){
                dp[i] = true;
                break;
            }
        }
    }

    cout << (dp[n] ? "Win" : "Lose") << "\n";

    return 0;
}
0