結果

問題 No.7 プライムナンバーゲーム
ユーザー chakkuchakku
提出日時 2015-10-17 17:03:05
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 93 ms / 5,000 ms
コード長 1,308 bytes
コンパイル時間 854 ms
コンパイル使用メモリ 72,176 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-09 03:51:53
合計ジャッジ時間 2,156 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,820 KB
testcase_01 AC 2 ms
6,948 KB
testcase_02 AC 93 ms
6,948 KB
testcase_03 AC 6 ms
6,944 KB
testcase_04 AC 3 ms
6,948 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 25 ms
6,944 KB
testcase_07 AC 16 ms
6,944 KB
testcase_08 AC 7 ms
6,944 KB
testcase_09 AC 39 ms
6,944 KB
testcase_10 AC 2 ms
6,948 KB
testcase_11 AC 16 ms
6,948 KB
testcase_12 AC 64 ms
6,944 KB
testcase_13 AC 69 ms
6,944 KB
testcase_14 AC 90 ms
6,948 KB
testcase_15 AC 86 ms
6,944 KB
testcase_16 AC 79 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <cstring>
#include <climits>
#include <cmath>
using namespace std;

#define rep(i,n) for(ll i=0;i<n;i++)
#define REP(i,x,n) for(ll i=x;i<n;i++)
#define ALL(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<":"<<x<<endl
#define debug2(x,y) cout<<#x<<":"<<#y<<"=="<<x<<":"<<y<<endl
const int INF = INT_MAX / 3;
const int dx[] = { 1, 0, -1, 0 }, dy[] = { 0, 1, 0, -1 };
#define MOD 1000000007
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;

int N;
bool sosu[10001];
int memo[2][10001];

//meが0で先手,1で後手。nは受け取る数
bool rec(int me,int n){
	if (n == 0 || n == 1) return true;
	if (memo[me][n] != -1) return memo[me][n];
	int next = (me + 1) % 2;
	for (int i = 0; i < n; i++){
		if (sosu[i]){
			if (!rec(next, n - i)) return memo[me][n]=true;
		}
	}
	return memo[me][n]=false;
}

int main(){
	cin >> N;
	rep(i, 10001) sosu[i] = true;
	sosu[0] = false;
	sosu[1] = false;
	memset(memo, -1, sizeof(memo));
	for (int i = 2; i <= sqrt(10001); i++){
		if (sosu[i]){
			for (int j = i * 2; j < 10001; j += i){
				sosu[j] = false;
			}
		}
	}
	if (rec(0, N)){
		cout << "Win" << endl;
	} else{
		cout << "Lose" << endl;
	}
	return 0;
}
0