結果

問題 No.7 プライムナンバーゲーム
ユーザー TwizzTwizz
提出日時 2017-05-05 23:13:10
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 840 bytes
コンパイル時間 1,169 ms
コンパイル使用メモリ 145,228 KB
実行使用メモリ 4,352 KB
最終ジャッジ日時 2023-10-12 10:11:07
合計ジャッジ時間 3,675 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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, i+1, 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