結果

問題 No.7 プライムナンバーゲーム
ユーザー nagisa5101nagisa5101
提出日時 2023-03-24 20:59:27
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 15 ms / 5,000 ms
コード長 1,843 bytes
コンパイル時間 4,840 ms
コンパイル使用メモリ 265,256 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-18 20:37:33
合計ジャッジ時間 5,156 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

using namespace std;
using namespace atcoder;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repll(i, n) for (long long i = 0; i < (long long)(n); i++)
#define rep2(i, n, m) for (int i = n; i < (int)(m); i++)
#define repll2(i, n, m) for (long long i = n; i < (long long)(m); i++)
#define all(v) v.begin(),v.end()
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vvvl = vector<vvl>;
using vld = vector<ld>;
using vvld = vector<vld>;

int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,1,-1};

const double PI = acos(-1);
//const ll MOD=1e9+7;
//const ll MOD=998244353;
const ll INF=(1LL<<60);
const int INF2=(1<<30);
//using mint=modint1000000007;
//using mint=modint998244353;

std::vector<int> Eratosthenes( const int N )
{
    std::vector<bool> is_prime( N + 1 );
    for( int i = 0; i <= N; i++ )
    {
        is_prime[ i ] = true;
    }
    std::vector<int> P;
    for( int i = 2; i <= N; i++ )
    {
        if( is_prime[ i ] )
        {
            for( int j = 2 * i; j <= N; j += i )
            {
                is_prime[ j ] = false;
            }
            P.emplace_back( i );
        }
    }
    return P;
}


vi er;
vi memo(10001,-1);

int dp(int i){
    if(memo[i]!=-1)return memo[i];
    if(i==0||i==1)return 1;
    int ans=0;
    for(auto p:er){
        if(p>i)break;
        ans=max(ans,1-dp(i-p));
    }
    memo[i]=ans;
    return ans;
}




int main() {
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    int n;cin>>n;
    er=Eratosthenes(n);
    if(dp(n))cout<<"Win"<<endl;
    else cout<<"Lose"<<endl;
    return 0;
}
0