結果
| 問題 |
No.7 プライムナンバーゲーム
|
| コンテスト | |
| ユーザー |
wonda_t_coffee
|
| 提出日時 | 2020-02-27 10:27:57 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 370 ms / 5,000 ms |
| コード長 | 1,591 bytes |
| コンパイル時間 | 1,070 ms |
| コンパイル使用メモリ | 88,924 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-10-01 16:31:32 |
| 合計ジャッジ時間 | 3,931 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 17 |
ソースコード
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <ctime>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
using namespace std;
int n;
map<int, bool> memo;
const int MAX = 10000;
bool isPrime[MAX + 1];
void sieve() {
for (int i = 0; i <= MAX; i++) isPrime[i] = true;
isPrime[0] = false;
isPrime[1] = false;
for (int i = 4; i <= n; i += 2) {
isPrime[i] = false;
}
int lim = (int)sqrt(n);
// cout << "lim = " << lim << endl;
for (int i = 3; i <= lim; i += 2) {
for (int j = 3; i * j <= n; j += 2) {
isPrime[i * j] = false;
}
}
}
int solve(int m) {
if (memo.find(m) != memo.end()) {
return memo[m];
}
for (int i = 2; i < m; i++) {
if (!isPrime[i]) continue;
// cout << "m = " << m << ", i = " << i << endl;
if (m - i > 1 && !solve(m - i)) {
memo[m] = true;
return true;
}
}
memo[m] = false;
return false;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cin >> n;
sieve();
memo[0] = false;
memo[1] = false;
memo[2] = false;
// for (int i = 0; i <= n; i++) {
// if (isPrime[i]) {
// cout << i << endl;
// }
// }
if (solve(n)) {
cout << "Win" << endl;
} else {
cout << "Lose" << endl;
}
// for (int i = 0; i <= n; i++) {
// cout << "memo[" << i << "] = " << memo[i] << endl;
// }
}
wonda_t_coffee