結果
| 問題 |
No.7 プライムナンバーゲーム
|
| コンテスト | |
| ユーザー |
xxxasdfghjk
|
| 提出日時 | 2018-08-13 23:01:24 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 25 ms / 5,000 ms |
| コード長 | 1,441 bytes |
| コンパイル時間 | 672 ms |
| コンパイル使用メモリ | 75,668 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-10-01 16:14:00 |
| 合計ジャッジ時間 | 1,407 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 17 |
ソースコード
#include<cstdio>
#include<queue>
#include<utility>
#include<cstring>
#include<stack>
#include<algorithm>
#include<cmath>
#include<iostream>
#include<map>
#define MAX_N 100001
#define INF_INT 2147483647
#define INF_LL 9223372036854775807
#define REP(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
bool cmp_P(const P &a,const P &b){
return a.second < b.second;
}
int n;
bool primes[10001];
vector<int> p(0);
void setprime(){
fill(primes,primes+10001,true);
for(int i=2;i<10001;i++){
if(primes[i])
for(int j=i+i;j<10001;j+=i){
primes[j] = false;
}
}
}
int dp[10001][2];
bool solve(int N,int t){
if(dp[N][t] != -1)
return dp[N][t];
if(N == 0 || N == 1){
if(t)
return true;
else
return false;
}else{
for(int i=0;i<p.size();i++){
if(N-p[i] >= 0){
if(t == 0){
if(!solve(N-p[i],1))
return dp[N][t] = false;
}else{
if(solve(N-p[i],0))
return dp[N][t] = true;
}
}
}
}
if(t == 0)
return dp[N][t] = true;
else
return dp[N][t] = false;
}
int main()
{
int N;
REP(i,10001)REP(j,2)dp[i][j] = -1;
cin >> N;
setprime();
for(int i=2;i<10001;i++){
if(primes[i]){
p.push_back(i);
}
}
if(solve(N,1))
cout << "Win" << endl;
else
cout << "Lose" << endl;
return 0;
}
xxxasdfghjk