結果

問題 No.7 プライムナンバーゲーム
ユーザー ransewhaleransewhale
提出日時 2018-07-15 02:11:58
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 11 ms / 5,000 ms
コード長 1,099 bytes
コンパイル時間 1,945 ms
コンパイル使用メモリ 165,636 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-09 04:30:37
合計ジャッジ時間 2,461 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<int, int> P;
typedef pair<int, P> E;
#define MOD (1000000007ll)
#define l_ength size
#define EPS (1e-10)

void add_mod(ll &a, ll b){
	a += b;
	a %= MOD;
}

void mul_mod(ll &a, ll b){
	a *= b;
	a %= MOD;
}

int f(int x){
	return (x<10)?x:x%10+f(x/10);
}

vector<int> v;

int l;
bool isp[12345],memo[12345],done[12345];

bool dp(int x){
	int i = 0;
	if(done[x]){
		return memo[x];
	}
	done[x] = true;
	if(x < 2){
		memo[x] = true;
		return memo[x];
	}
	memo[x] = false;
	for(i=0; i<l; ++i){
		if(v[i] > x){
			break;
		}
		if(!dp(x-v[i])){
			memo[x] = true;
			break;
		}
	}
	return memo[x];
}

int main(void){
	int n,i,j;
	fill(isp,isp+12345,true);
	fill(done,done+12345,false);
	isp[0] = false;
	isp[1] = false;
	for(i=2; i<=123; ++i){
		if(!isp[i]){
			continue;
		}
		for(j=i*2; j<=12345; j+=i){
			isp[j] = false;
		}
	}
	for(i=2; i<=12345; ++i){
		if(isp[i]){
			v.push_back(i);
		}
	}
	l = v.l_ength();
	cin >> n;
	cout << ((dp(n))?"Win":"Lose") << endl;
	return 0;
}
0