結果
問題 | No.7 プライムナンバーゲーム |
ユーザー |
![]() |
提出日時 | 2019-10-12 17:07:14 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 5 ms / 5,000 ms |
コード長 | 671 bytes |
コンパイル時間 | 1,760 ms |
コンパイル使用メモリ | 171,288 KB |
実行使用メモリ | 6,824 KB |
最終ジャッジ日時 | 2024-10-01 16:24:42 |
合計ジャッジ時間 | 2,112 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 17 |
ソースコード
#include <bits/stdc++.h>using namespace std;int N;int dp[10101];vector<int> primes;int dfs(int v) {if (v <= 1) return 1;if (dp[v] != 0) return dp[v];for (auto x : primes) {if (v < x) break;if (dfs(v - x) == 2) return dp[v] = 1;}return dp[v] = 2;}int main() {cin >> N;primes.assign(N + 1, 0);for (int i = 2; i <= N; ++i) primes[i] = i;for (int i = 2; i * i <= N; ++i) {if (primes[i]) {for (int j = i * i; j <= N; j += i) primes[j] = 0;}}primes.erase(remove(primes.begin(), primes.end(), 0), primes.end());if (dfs(N) == 1) {cout << "Win\n";} else {cout << "Lose\n";}return 0;}