結果

問題 No.7 プライムナンバーゲーム
ユーザー soupesuteakasoupesuteaka
提出日時 2014-12-29 11:44:59
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 12 ms / 5,000 ms
コード長 1,058 bytes
コンパイル時間 791 ms
コンパイル使用メモリ 90,232 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-09 03:41:09
合計ジャッジ時間 1,494 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <cstdio>
#include <sstream>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <set>
#include <map>
#include <list>
#include <iomanip>

#define INF 1000000001
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i >= (b); i--)

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
const double PI = acos(-1.0);

int N, K;
vector<int> primes;

void getprimes(int n)
{
	vector<bool> v(n+1);
	int d=2;
	FOR(d,2,n+1) {
		if (v[d]) continue;
		primes.push_back(d);
		int tmp=d*2;
		while (tmp <= n) {
			v[tmp] = true;
			tmp += d;
		}
	}
}

int main()
{
	ios::sync_with_stdio(false);

	cin >> N;
	getprimes(N);

	vector<bool> win(N+1, false);
	win[0] = win[1] = true;

	FOR(n,2,N+1) {
		bool flg = true;
		FOR(i,0,primes.size()) {
			if (primes[i] > n) break;
			flg &= win[n-primes[i]];
		}
		win[n] = !flg; 
	}

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

	return 0;
}
0