結果

問題 No.7 プライムナンバーゲーム
ユーザー NasatameNasatame
提出日時 2017-09-09 10:38:11
言語 C++11
(gcc 11.4.0)
結果
RE  
実行時間 -
コード長 1,730 bytes
コンパイル時間 926 ms
コンパイル使用メモリ 99,272 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-24 23:43:26
合計ジャッジ時間 4,457 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <array>
#include <map>
#include <algorithm>
#include <cmath>
#include <vector>
#include <fstream>
#include <string>
#include <random>
#include <queue>
#include <iomanip>
#include <functional>
#include <climits>

using namespace std;

using ll = long long int;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vll = std::vector<ll>;
using vpll = std::vector<pll>;
using vpii = std::vector<pii>;
using vi = std::vector<int>;
using vvi = std::vector<vi>;

const ll mod197 = 1000000007LL;
const ll INF = INT_MAX;

const double PI11 = 3.14159265359;

vi prime;
vvi memo(10010,vi(2,0));


//敗北条件0,1を作る。
//現在の値を入れて。
//勝った方を返す関数
//はじめのターンは0つまり先攻は0
//後攻は1
int solve(int i,int depth) {

	if (memo[i][depth % 2] != -1) {
		return memo[i][depth % 2];
	}

	if (i == 0 || i == 1) {
		return depth;
	}
	int res = 0;

	int j = 1;
	while (j <= prime.size() && i >= prime[prime.size()-j]) {

		res = solve(i - prime[j], depth + 1);

		if (depth % 2 == 0) {
			if (res % 2 == 0) {
				return memo[i][depth % 2] = res;
			}
		}
		else {
			if (res % 2 == 1) {
				return memo[i][depth % 2] = res;
			}
		}
		j++;
	}

	return memo[i][depth % 2] = depth+1;
}

void enum_prime(int n) {

	for (int i = 2; i <= n; i++) {
		if (memo[i][0] == false) {
			for (int j = i; j <= n; j += i) {
				memo[j][0] = true;
			}
			prime.push_back(i);
		}
	}
	reverse(prime.begin(), prime.end());
}

int main() {

	int n;
	cin >> n;
	enum_prime(n);

	for (int i = 0; i < 10010; i++)
		for (int j = 0; j < 2; j++)
			memo[i][j] = -1;

	if (solve(n,0) % 2 == 0) {
		cout << "Win" << endl;
	}
	else {
		cout << "Lose" << endl;
	}


	return 0;
}

0