結果

問題 No.7 プライムナンバーゲーム
ユーザー kkslucy1kkslucy1
提出日時 2018-03-10 00:24:14
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 667 bytes
コンパイル時間 1,306 ms
コンパイル使用メモリ 161,672 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-19 06:01:55
合計ジャッジ時間 2,263 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 1 ms
5,376 KB
testcase_05 WA -
testcase_06 AC 9 ms
5,376 KB
testcase_07 AC 5 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 6 ms
5,376 KB
testcase_12 AC 26 ms
5,376 KB
testcase_13 AC 27 ms
5,376 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 31 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

int main() {
	int n;
	cin >> n;
	vector<int> p(n + 1);
	for (int i = 0;i <= n;i++) {
		p[i] = -1;
	}
	for (int i = 2;i <= n;i++) {
		if (p[i] == -1) {
			p[i] = 1;
			for (int j = 2;j*i <= n;j++) {
				p[j*i] = 0;
			}
		}
	}
	vector<bool> win(n + 1);//iで自分に番が回ってきたときに勝てるか
	win[0] = true;
	win[1] = true;
	for (int i = 2;i <= n;i++) {
		bool b = true;
		for (int j = 2;j <= i;j++) {
			if (p[j]&&win[i-p[j]]) {	//次の番で相手が勝てるとき、自分は負ける
				b = false;
				break;
			}
		}
		win[i] = b;
	}
	cout << (win[n] ? "Win" : "Lose") << endl;




	return 0;
}
0