結果

問題 No.7 プライムナンバーゲーム
ユーザー kakeyamaykakeyamay
提出日時 2019-07-01 12:27:29
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 32 ms / 5,000 ms
コード長 513 bytes
コンパイル時間 2,234 ms
コンパイル使用メモリ 198,984 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-09 04:39:22
合計ジャッジ時間 3,241 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

int main() {
	
	int N;
	std::cin >> N;
	std::list<int> primes;
	primes.push_back(2);
	for(int i=3;i<=N;i+=2){
		if(std::any_of(begin(primes),end(primes),[&](int p){ return i%p==0; }))continue;
		primes.push_back(i);
	}
	std::vector<bool> dp(N+1,false);
	dp[0]=dp[1]=true;
	for(int i=2;i<=N;++i){
		for(auto&v:primes){
			if(i<v)break;
			//遷移先は相手の勝敗
			if(dp[i-v])continue;
			dp[i] = true;
		}
	}
	bool ans = dp[N];
	std::cout << (ans?"Win":"Lose") << std::endl;
}
0