結果
問題 |
No.7 プライムナンバーゲーム
|
ユーザー |
![]() |
提出日時 | 2024-02-14 02:35:32 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 12 ms / 5,000 ms |
コード長 | 950 bytes |
コンパイル時間 | 2,920 ms |
コンパイル使用メモリ | 248,012 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-09-28 18:42:55 |
合計ジャッジ時間 | 3,789 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 17 |
ソースコード
#include <bits/stdc++.h> using namespace std; using i64 = long long; int main() { cin.tie(nullptr)->sync_with_stdio(false); auto solve = [&]() { int n; cin >> n; auto isPrime = [&](int n) { if (n == 1) { return false; } for (int i = 2; i * i <= n; i++) { if (n % i == 0) { return false; } } return true; }; vector<int> primes; for (int x = 1; x <= n; x++) { if (isPrime(x)) { primes.push_back(x); } } vector<int> dp(n); for (int i = 2; i <= n; i++) { for (auto p : primes) { if (i - p <= 1) { break; } dp[i] |= !dp[i - p]; } } cout << (dp[n] ? "Win" : "Lose") << '\n'; }; solve(); return 0; }