結果
| 問題 |
No.7 プライムナンバーゲーム
|
| コンテスト | |
| ユーザー |
troro_kelp
|
| 提出日時 | 2018-12-30 17:06:13 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 5,000 ms |
| コード長 | 1,938 bytes |
| コンパイル時間 | 865 ms |
| コンパイル使用メモリ | 96,928 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-10-01 16:16:55 |
| 合計ジャッジ時間 | 1,464 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 17 |
ソースコード
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <stack>
#include <algorithm>
#include <iomanip>
#include <map>
#include <queue>
#include <functional>
#include <numeric>
using ll = long long;
using namespace std;
const ll MOD = 1e9 + 7;
vector<int> prime;
bool sieve[200010];
int key[100010];
int Hash[55];
int visited[2][10010]; //0-先行 1-後行 現在の値
bool dfs(int T, int N)
{
if (N == 0 || N == 1)
{
return T == 0 ? 1 : 0;
}
if (visited[T][N] >= 0)
{
return visited[T][N];
}
if (T == 0)
{
for (auto &x : prime)
{
if (N - x >= 0)
{
if (dfs(1, N - x))
{
visited[T][N] = 1;
return 1;
}
}
}
visited[T][N] = 0;
return 0;
}
else
{
for (auto &x : prime)
{
if (N - x >= 0)
{
if (!dfs(0, N - x))
{
visited[T][N] = 0;
return 0;
}
}
}
visited[T][N] = 1;
return 1;
}
}
int main(void)
{
int N;
cin >> N;
for (int i = 0; i < 2; ++i)
{
for (int j = 0; j < 10010; ++j)
{
visited[i][j] = -1;
}
}
for (int i = 0; i < 10010; ++i)
sieve[i] = true;
sieve[0] = sieve[1] = false;
for (int i = 2; i * i < 10010; ++i)
{
if (sieve[i])
{
for (int j = 2; i * j < 10010; ++j)
{
sieve[i * j] = false;
}
}
}
for (int i = 0; i <= N; ++i)
if (sieve[i])
prime.emplace_back(i);
reverse(prime.begin(), prime.end());
if (dfs(0, N))
cout << "Win" << endl;
else
cout << "Lose" << endl;
return 0;
}
troro_kelp