結果
| 問題 |
No.7 プライムナンバーゲーム
|
| コンテスト | |
| ユーザー |
purple_jwl
|
| 提出日時 | 2015-03-05 00:22:23 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 18 ms / 5,000 ms |
| コード長 | 1,144 bytes |
| コンパイル時間 | 1,424 ms |
| コンパイル使用メモリ | 161,944 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-10-01 15:30:26 |
| 合計ジャッジ時間 | 2,112 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 17 |
ソースコード
#include <bits/stdc++.h>
#define REP(i, x, n) for(int i = x; i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define F first
#define S second
#define mp make_pair
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
const int MAX = 10000;
vector<int> prime;
bool isPrime[MAX + 1];
void sieve(int N){
prime.clear();
for(int i = 0; i <= N; i++) {
isPrime[i] = true;
}
isPrime[0] = isPrime[1] = false;
for(int i = 2; i <= N; i++) {
if(!isPrime[i]) continue;
prime.push_back(i);
for(int j = i + i; j <= N; j += i) {
isPrime[j] = false;
}
}
}
int N;
int memo[MAX + 1];
bool rec(int n) {
if(n == 0 || n == 1) return true;
if(memo[n] != -1) return memo[n];
bool res = false;
rep(i, prime.size()) {
if(n < prime[i]) break;
res |= !rec(n - prime[i]);
}
return memo[n] = res;
}
int main() {
// ios_base::sync_with_stdio(false);
cin >> N;
sieve(N);
memset(memo, -1, sizeof(memo));
cout << (rec(N) ? "Win" : "Lose") << endl;
return 0;
}
purple_jwl