結果

問題 No.7 プライムナンバーゲーム
ユーザー NasatameNasatame
提出日時 2017-09-09 10:13:08
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,567 bytes
コンパイル時間 1,719 ms
コンパイル使用メモリ 93,800 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-07 05:26:01
合計ジャッジ時間 1,881 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

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

ソースコード

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>;

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

const double PI11 = 3.14159265359;

vi prime;
int desk[10010] = {};
int memo[10010][2] = {};


//勝利条件2,3を作る。
int solve(int i,int depth) {

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

	if (i == 2 || i == 3) {
		return depth+1;
	}

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

	int res = 0;

	int j = 0;
	while (i >= prime[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() {

	for (int i = 2; i <= 10000; i++) {
		if (desk[i] == false) {
			for (int j = i; j <= 10000; j += i) {
				desk[j] = true;
			}
			prime.push_back(i);
		}
	}

}

int main() {

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

	fill(memo[0], memo[0] + 10010, -1);
	fill(memo[1], memo[1] + 10010, -1);

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


	return 0;
}

0