結果

問題 No.7 プライムナンバーゲーム
ユーザー TwizzTwizz
提出日時 2017-05-05 23:08:03
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 838 bytes
コンパイル時間 1,183 ms
コンパイル使用メモリ 144,968 KB
実行使用メモリ 4,376 KB
最終ジャッジ日時 2023-10-12 10:14:22
合計ジャッジ時間 4,491 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include"bits/stdc++.h"
//#include<bits/stdc++.h>
using namespace std;
#define print(x) cout<<x<<endl;
#define rep(i,a,b) for(int i=a;i<b;i++)
typedef long long ll;
//const int mod = 1e9 + 7;

int sos[10002];
int dp[2][10002];

void so(int n){
	rep(i, 2, n + 1) {
		rep(j, 3, n + 1) {
			if (j%i == 0)sos[j] = 0;
		}
	}
	return;
}

int solve(int i,int n) {
	if (i == 1 && (n == 0 || n == 1)) { 
		return dp[i][n] = 0; 
	}
	else if (i == 0 && (n == 0 || n == 1)) { 
		return dp[i][n] = 1;
	}
	if (dp[i][n] != -1)
	{
		return dp[i][n];
	}
	rep(j, 2, n) {
		if (sos[j] == 1 && solve(abs(i-1), n - j)) { 
			return dp[abs(i - 1)][n - j] = 1;
		}
	}
	return dp[i][n] = 0;
}

int main() {
	int n;
	cin >> n;
	rep(i, 0, n)sos[i] = 1;
	so(n);
	memset(dp, -1, sizeof(dp));
	if (solve(0, n)) { print("Win"); }
	else { print("Lose"); }
	return 0;
}
0