結果
問題 | No.7 プライムナンバーゲーム |
ユーザー | MitI_7 |
提出日時 | 2016-03-05 21:29:10 |
言語 | C++11 (gcc 11.4.0) |
結果 |
AC
|
実行時間 | 402 ms / 5,000 ms |
コード長 | 1,622 bytes |
コンパイル時間 | 1,063 ms |
コンパイル使用メモリ | 96,204 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-04-09 03:56:20 |
合計ジャッジ時間 | 4,376 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
6,820 KB |
testcase_01 | AC | 1 ms
6,944 KB |
testcase_02 | AC | 395 ms
6,948 KB |
testcase_03 | AC | 22 ms
6,944 KB |
testcase_04 | AC | 6 ms
6,944 KB |
testcase_05 | AC | 6 ms
6,944 KB |
testcase_06 | AC | 116 ms
6,948 KB |
testcase_07 | AC | 76 ms
6,948 KB |
testcase_08 | AC | 32 ms
6,948 KB |
testcase_09 | AC | 177 ms
6,948 KB |
testcase_10 | AC | 2 ms
6,948 KB |
testcase_11 | AC | 77 ms
6,944 KB |
testcase_12 | AC | 289 ms
6,948 KB |
testcase_13 | AC | 307 ms
6,944 KB |
testcase_14 | AC | 402 ms
6,948 KB |
testcase_15 | AC | 380 ms
6,948 KB |
testcase_16 | AC | 351 ms
6,948 KB |
ソースコード
#include <iostream> #include <string> #include <vector> #include <queue> #include <stack> #include <map> #include <algorithm> #include <numeric> #include <functional> #include <set> #include <sstream> #include <cstdio> #include <cstdlib> #include <cstring> #include <cmath> #include <cctype> #include <climits> #include <fstream> #include <bitset> #include <time.h> #define ll long long #define FOR(i,a,b) for(int i= (a); i<((int)b); ++i) #define RFOR(i,a) for(int i=(a); i >= 0; --i) #define FOE(i,a) for(auto i : a) #define ALL(c) (c).begin(), (c).end() #define RALL(c) (c).rbegin(), (c).rend() #define DUMP(x) cerr << #x << " = " << (x) << endl; #define SUM(x) std::accumulate(ALL(x), 0LL) #define EPS 1e-14 using namespace std; // nまでの素数のリストを作成(nを含む) vector<long long> getPrimeList(int n) { vector<bool> dp(n + 1, false); dp[0] = dp[1] = true; vector<long long> primeList; for (int i = 2; i < n + 1; ++i) { if (dp[i]) { continue; } primeList.push_back(i); for (int j = i; j < n + 1; j += i) { dp[j] = true; } } return primeList; } map<int, bool> memo; bool win(int n, const vector<ll> &primes) { if (memo.find(n) != memo.end()) { return memo[n]; } FOE(p, primes) { if (n - p > 1) { if (!win(n - p, primes)) { return memo[n] = true; } } } return memo[n] = false; } int main(int argc, char *argv[]) { int N; cin >> N; vector<ll> p = getPrimeList(N); cout << (win(N, p) ? "Win" : "Lose") << endl; return 0; }