結果

問題 No.7 プライムナンバーゲーム
ユーザー togari_takamototogari_takamoto
提出日時 2015-12-13 02:33:17
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 7 ms / 5,000 ms
コード長 1,038 bytes
コンパイル時間 793 ms
コンパイル使用メモリ 94,152 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-09 03:52:42
合計ジャッジ時間 1,612 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <array>
#include <algorithm>
#include <string>
#include <map>
#include <queue>
#include <iomanip>
#include <numeric>
#include <memory>
#include <limits.h>
#include <set>
#include <cassert>
#include <cmath>
#include <bitset>
using namespace std;

typedef long long ll;

#define REP(i,n) for(ll i=0; i<(n); ++i)
#define TEN(x) ((ll)1e##x)
#define ALL(v) (v).begin(), (v).end()

// エラトステネスのふるい O(n log log n) : t[i] = true ⇔ iが素数 (i <= n)
vector<int> sieve_of_eratosthenes(ll n) {
	vector<int> t(n+1, true); t[0] = t[1] = false;
	for(ll i = 2; i <= n; ++i) if (t[i]){
		for(ll j = 2*i; j <= n; j += i) t[j] = false;
	}
	return t;
}

int main() {
	ll n;
	cin >> n;

	auto t = sieve_of_eratosthenes(n);
	vector<ll> v; v.reserve(n);
	REP(i, n + 1) if (t[i]) v.push_back(i);

	vector<bool> win(n + 1, true);
	for (ll i = 2; i < n + 1; ++i) win[i] = !all_of(ALL(v), [&](ll x) { return i < x || win[i-x]; });
	std::cout << (win[n] ? "Win" : "Lose") << endl;
	return 0;
}
0