結果
問題 |
No.7 プライムナンバーゲーム
|
ユーザー |
![]() |
提出日時 | 2023-05-21 16:07:59 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 6 ms / 5,000 ms |
コード長 | 1,462 bytes |
コンパイル時間 | 1,303 ms |
コンパイル使用メモリ | 125,184 KB |
最終ジャッジ日時 | 2025-02-13 03:57:56 |
ジャッジサーバーID (参考情報) |
judge3 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 17 |
ソースコード
#include <iostream> #include <iomanip> #include <vector> #include <algorithm> #include <functional> #include <cmath> #include <string> #include <queue> #include <map> #include <bitset> #include <set> #include <stack> #include <numeric> #include <unordered_map> #include <random> using namespace std; using ll = long long; using vi = vector<int>; using vvi = vector<vi>; using vl = vector<ll>; using vvl = vector<vl>; using vb = vector<bool>; using vvb = vector<vb>; using vd = vector<double>; using vs = vector<string>; using pii = pair<int, int>; using pll = pair<ll, ll>; using pdd = pair<double, double>; using vpii = vector<pii>; using vpll = vector<pll>; using vpdd = vector<pdd>; const int inf = (1 << 30) - 1; const ll INF = 1LL << 60; //const int MOD = 1000000007; const int MOD = 998244353; vi getPrimes(int N) { vector<bool> isPrime(N + 1, true); isPrime[0] = isPrime[1] = false; for (int p = 2; p * p <= N; ++p) { if (!isPrime[p]) continue; for (int q = p * 2; q <= N; q += p) { isPrime[q] = false; } } vi ret; for (int i = 2; i < N; i++) { if (isPrime[i]) ret.push_back(i); } return ret; } int main() { int n; cin >> n; vi primes = getPrimes(n); vb dp(n + 1, false); dp[0] = dp[1] = true; for (int i = 2; i <= n; i++) { for (auto& p : primes) { if (p > i) break; if (dp[i - p] == false) { dp[i] = true; break; } } } if (dp[n]) cout << "Win" << endl; else cout << "Lose" << endl; return 0; }