結果

問題 No.7 プライムナンバーゲーム
ユーザー komori3komori3
提出日時 2017-08-25 01:34:34
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,570 bytes
コンパイル時間 824 ms
コンパイル使用メモリ 69,112 KB
実行使用メモリ 4,508 KB
最終ジャッジ日時 2023-08-05 17:29:58
合計ジャッジ時間 1,871 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <stack>
#include <utility>
#include <queue>
//#include <random>
#include <time.h>

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)

#define SWAP(a,b) (a ^= b,b = a ^ b,a ^= b)
#define swap(type,a,b) do{type _c;_c=a;a=b;b=_c;}while(0)

using namespace std;
typedef long long int lint;

template <typename _Ty>
ostream& operator << (ostream& ostr, const vector<_Ty>& v) {
	if (v.empty()) {
		cout << "{ }";
		return ostr;
	}
	cout << "{" << v.front();
	for (auto itr = ++v.begin(); itr != v.end(); itr++) {
		cout << ", " << *itr;
	}
	cout << "}";
	return ostr;
}

int yuki0007()
{
	int N;
	cin >> N;

	vector<bool> sieve(N + 1, true);

	sieve[0] = sieve[1] = false;
	for (int i = 2; i * i <= N; i++) {
		if (!sieve[i]) continue;
		for (int j = i * i; j <= N; j += i)
			sieve[j] = false;
	}

	vector<int> p;
	for (int i = 0; i < sieve.size(); i++)
		if (sieve[i])
			p.push_back(i);


	vector<bool> win(N + 1, false);

	for (int i = 2; i <= N; i++) {
		if (sieve[i - 1] || sieve[i]) {
			win[i] = true;
			continue;
		}
		for (int j = 0; j < p.size() && p[j] <= i; j++)
			if (!win[i - p[j]]) {
				win[i] = true;
				break;
			}
	}

	cout << (win[N] ? "Win" : "Lose") << endl;

	return 0;
}


int main()
{
	//clock_t start, end;
	//start = clock();

	yuki0007();

	//end = clock();
	//printf("%d msec.\n", end - start);

	return 0;
}
0