結果

問題 No.7 プライムナンバーゲーム
ユーザー kakeyamaykakeyamay
提出日時 2019-07-01 07:55:12
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 514 bytes
コンパイル時間 1,975 ms
コンパイル使用メモリ 203,428 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-22 09:12:39
合計ジャッジ時間 3,330 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 WA -
testcase_02 AC 31 ms
4,376 KB
testcase_03 AC 3 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 WA -
testcase_06 AC 10 ms
4,376 KB
testcase_07 AC 7 ms
4,380 KB
testcase_08 AC 4 ms
4,380 KB
testcase_09 WA -
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 7 ms
4,380 KB
testcase_12 AC 23 ms
4,376 KB
testcase_13 AC 24 ms
4,376 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 27 ms
4,376 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":"Loose") << std::endl;
}
0