結果

問題 No.7 プライムナンバーゲーム
ユーザー odan3240odan3240
提出日時 2015-12-26 17:37:42
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 108 ms / 5,000 ms
コード長 1,330 bytes
コンパイル時間 552 ms
コンパイル使用メモリ 86,476 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-07-24 20:28:29
合計ジャッジ時間 2,082 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <algorithm>
#include <functional>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <climits>

#define all(c) (c).begin(), (c).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second

const int INF=100000000;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
using namespace std;
typedef pair<int ,int > P;
typedef long long ll;

bool isPrime[10004];
int N;
int dp[10004];
int dfs(int n,int d) {
    if(n==0||n==1) return 1;
    //if(n==2||n==3) return 1;
    if(dp[n]!=100) return dp[n];
    int ret = -INF;
    for(int i=n;i>=2;i--) {
        if(isPrime[i]&&n-i>=0) ret = max(ret,-dfs(n-i,d+1));
    }

    //cout<<string(d,' ')<<n<<": "<<ret<<endl;
    return dp[n]=ret;
}
int main() {
    rep(i,10004) dp[i]=100;
    rep(i,10004) isPrime[i]=true;
    isPrime[0]=isPrime[1]=false;
    for(int i=2;i<10004;i++) {
        if(isPrime[i]) for(int j=2*i;j<10004;j+=i) isPrime[j]=false;
    }
    cin>>N;
    if(dfs(N,0)==1) {
        cout<<"Win"<<endl;
    }
    else {
        cout<<"Lose"<<endl;
    }
    return 0;
}
0