結果

問題 No.7 プライムナンバーゲーム
ユーザー nnasennnasen
提出日時 2017-12-09 11:14:42
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 159 ms / 5,000 ms
コード長 722 bytes
コンパイル時間 1,713 ms
コンパイル使用メモリ 166,144 KB
実行使用メモリ 6,952 KB
最終ジャッジ日時 2024-04-09 04:23:54
合計ジャッジ時間 3,474 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,816 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 159 ms
6,944 KB
testcase_03 AC 10 ms
6,944 KB
testcase_04 AC 4 ms
6,944 KB
testcase_05 AC 4 ms
6,948 KB
testcase_06 AC 45 ms
6,948 KB
testcase_07 AC 30 ms
6,944 KB
testcase_08 AC 14 ms
6,948 KB
testcase_09 AC 69 ms
6,952 KB
testcase_10 AC 1 ms
6,944 KB
testcase_11 AC 31 ms
6,944 KB
testcase_12 AC 112 ms
6,944 KB
testcase_13 AC 120 ms
6,948 KB
testcase_14 AC 158 ms
6,948 KB
testcase_15 AC 150 ms
6,944 KB
testcase_16 AC 138 ms
6,948 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define REP(i,n) FOR(i,0,n)
#define SZ(n) (int)(n).size()
#define ALL(n) (n).begin(), (n).end()
#define MOD 1000000007
#define INF 100000000
using namespace std;
typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PI;


int main() {
	int n;
	cin >> n;
	vector<bool> vb(10000, true);
	vb[0] = vb[1] = false;
	for (int i = 2; i * i < n; ++i) {
		if (vb[i]) {
			for (int j = i * 2; j < n; j += i) {
				vb[j] = false;
			}
		}
	}
	vector <bool> dp(10000);
	dp[0] = dp[1] = true;
	FOR(i, 2, n + 1) {
		REP(j, i + 1) {
			if (vb[j] && !dp[i - j]) {
				dp[i] = true;
			}
		}
	}
	cout << (dp[n] ? "Win" : "Lose") << endl;
	return 0;
}
0