結果

問題 No.7 プライムナンバーゲーム
ユーザー nnasennnasen
提出日時 2017-12-09 11:14:42
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 137 ms / 5,000 ms
コード長 722 bytes
コンパイル時間 1,513 ms
コンパイル使用メモリ 166,240 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-07-24 21:02:11
合計ジャッジ時間 3,255 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 137 ms
4,380 KB
testcase_03 AC 9 ms
4,380 KB
testcase_04 AC 3 ms
4,376 KB
testcase_05 AC 3 ms
4,380 KB
testcase_06 AC 39 ms
4,376 KB
testcase_07 AC 26 ms
4,376 KB
testcase_08 AC 12 ms
4,380 KB
testcase_09 AC 60 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 27 ms
4,376 KB
testcase_12 AC 97 ms
4,380 KB
testcase_13 AC 104 ms
4,380 KB
testcase_14 AC 137 ms
4,376 KB
testcase_15 AC 130 ms
4,380 KB
testcase_16 AC 119 ms
4,380 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