結果

問題 No.7 プライムナンバーゲーム
ユーザー kkslucy1kkslucy1
提出日時 2018-03-10 00:50:53
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 30 ms / 5,000 ms
コード長 704 bytes
コンパイル時間 1,299 ms
コンパイル使用メモリ 162,480 KB
実行使用メモリ 6,692 KB
最終ジャッジ日時 2024-04-09 04:26:23
合計ジャッジ時間 2,198 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,560 KB
testcase_01 AC 1 ms
6,688 KB
testcase_02 AC 30 ms
6,692 KB
testcase_03 AC 2 ms
6,688 KB
testcase_04 AC 2 ms
6,692 KB
testcase_05 AC 2 ms
6,692 KB
testcase_06 AC 7 ms
6,692 KB
testcase_07 AC 4 ms
6,688 KB
testcase_08 AC 3 ms
6,692 KB
testcase_09 AC 11 ms
6,692 KB
testcase_10 AC 2 ms
6,692 KB
testcase_11 AC 5 ms
6,692 KB
testcase_12 AC 21 ms
6,688 KB
testcase_13 AC 22 ms
6,688 KB
testcase_14 AC 30 ms
6,688 KB
testcase_15 AC 28 ms
6,692 KB
testcase_16 AC 26 ms
6,692 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で自分に番が回ってきたときに勝つならtrue
	win[0] = true;
	win[1] = true;
	for (int i = 2;i <= n;i++) {
		bool b = false;
		for (int j = 2;j <= i;j++) {
			if (p[j]&&!win[i-j]) {	//次の番で相手が勝てるとき、自分は負ける
				b = true;
				break;
			}
		}
		win[i] = b;
		//cout << i << "," << b << endl;
	}
	cout << (win[n] ? "Win" : "Lose") << endl;




	return 0;
}
0