結果
| 問題 |
No.7 プライムナンバーゲーム
|
| コンテスト | |
| ユーザー |
wonda_t_coffee
|
| 提出日時 | 2020-02-27 10:16:48 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,274 bytes |
| コンパイル時間 | 796 ms |
| コンパイル使用メモリ | 90,372 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-10-13 15:46:13 |
| 合計ジャッジ時間 | 4,377 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 14 WA * 3 |
ソースコード
#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;
bool isPrime[10001];
void sieve() {
for (int i = 0; i <= 10000; 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);
for (int i = 3; i * 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;
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;
if (solve(n)) {
cout << "Win" << endl;
} else {
cout << "Lose" << endl;
}
}
wonda_t_coffee