結果

問題 No.7 プライムナンバーゲーム
ユーザー 👑 yumechiyumechi
提出日時 2016-03-15 00:00:22
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 7 ms / 5,000 ms
コード長 1,334 bytes
コンパイル時間 588 ms
コンパイル使用メモリ 77,144 KB
実行使用メモリ 6,952 KB
最終ジャッジ日時 2024-04-09 03:56:56
合計ジャッジ時間 1,335 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <queue>

#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <functional>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define INF 1<<30
#define ALEN(ARR) (sizeof(ARR) / sizeof((ARR)[0]))
#define MP make_pair
#define mp make_pair
#define pb push_back
#define PB push_back
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define ll long long
#define ull unsigned long long
#define MOD 1000000007

bool dp[10010];

vector<int> getPrime(int n) {
	vector<int> ret;

	// errro check
	if(n <= 0) {
		cout << "can use this method negative number: getPrime " << n << endl;
		return ret;
	}

	FOR(i, 2, n) {
		bool flag = true;
		for(auto prime : ret) {
			if(i % prime == 0) {
				flag = false;
				break;
			}
		}

		if(flag) ret.pb(i);
	}

	return ret;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout.precision(16);

	int n;
	cin >> n;

	auto prime = getPrime(10000);

	dp[0] = dp[1] = true;
	REP(i, n+1) {
		for(auto j : prime) {
			if(i < j) break;
			if(!dp[i-j]) {
				dp[i] = true;
				break;
			}
		}
	}

	cout << (dp[n] ? "Win" : "Lose") << endl;
	return 0;
}
0