結果

問題 No.7 プライムナンバーゲーム
ユーザー rantdrantd
提出日時 2015-09-26 18:10:50
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,371 bytes
コンパイル時間 1,230 ms
コンパイル使用メモリ 145,756 KB
実行使用メモリ 8,120 KB
最終ジャッジ日時 2023-09-26 16:35:58
合計ジャッジ時間 7,873 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#define repu(i, a, b) for (int i = (a); i < (b); ++i)
#define repd(i, a, b) for (int i = (a); i > (b); --i)
#define mem(a, x) memset(a, x, sizeof(a))
#define all(a) a.begin(), a.end()
#define uni(a) a.erase(unique(all(a)), a.end())

typedef long long ll;
const int MOD = 1000000007;

template<class T, class U> inline T tmin(T a, U b) {return (a < b) ? a : b;}
template<class T, class U> inline T tmax(T a, U b) {return (a > b) ? a : b;}
template<class T, class U> inline void amax(T &a, U b) {if (b > a) a = b;}
template<class T, class U> inline void amin(T &a, U b) {if (b < a) a = b;}
template<class T> inline T tabs(T a) {return (a > 0) ? a : -a;}
template<class T> T gcd(T a, T b) {while (b != 0) {T c = a; a = b; b = c % b;} return a;}

const int N = 10005;
bool is_prime[N];
int dp[N];
vector<int> prime;

int go(int n) {
	if (dp[n] >= 0) return dp[n];
	int res = 0;
	repu(i, 0, prime.size()) {
		if (prime[i] >= n - 1) break;
		res |= 1 - go(n - prime[i]);
	}
	return res;
}

int main(int argc, char *argv[]) {
	ios_base::sync_with_stdio(false);
	
	int n;
	
	cin >> n;
	
	mem(is_prime, true);
	repu(i, 2, n + 1) {
		if (is_prime[i]) {
			prime.push_back(i);
			for (int j = i + i; j <= n; j += i) is_prime[j] = false;
		}
	}
	
	mem(dp, -1);
	dp[2] = 0;
	
	printf("%s\n", go(n) == 1 ? "Win" : "Lose");
	
	return 0;
}
0