結果
| 問題 |
No.7 プライムナンバーゲーム
|
| コンテスト | |
| ユーザー |
togari_takamoto
|
| 提出日時 | 2015-12-13 02:33:17 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 6 ms / 5,000 ms |
| コード長 | 1,038 bytes |
| コンパイル時間 | 905 ms |
| コンパイル使用メモリ | 94,008 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-10-01 15:38:08 |
| 合計ジャッジ時間 | 1,353 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 17 |
ソースコード
#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;
}
togari_takamoto