結果

問題 No.7 プライムナンバーゲーム
ユーザー misora192misora192
提出日時 2020-05-28 22:32:32
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 12 ms / 5,000 ms
コード長 845 bytes
コンパイル時間 1,575 ms
コンパイル使用メモリ 169,636 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-09 04:54:17
合計ジャッジ時間 2,406 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i=(0);i<(n);i++)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

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

	int n;
	cin >> n;

	vector<int> primes;
	vector<bool> isprime(n+1, true);
	isprime[0] = isprime[1] = false;
	for(int i = 2; i <= n; i++){
		if(isprime[i]) primes.push_back(i);
		for(int j = i * 2; j <= n; j += i) isprime[j] = false;
	}

	int dp[n+1];
	dp[0] = dp[1] = 1;
	
	for(int i = 2; i <= n; i++){
		int f = 1;
		for(int p : primes){
			if(p > i) break;
			if(dp[i - p] == 0) f = 0;
		}

		dp[i] = 1 - f;
	}

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