結果
問題 |
No.7 プライムナンバーゲーム
|
ユーザー |
![]() |
提出日時 | 2017-11-27 14:03:01 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 176 ms / 5,000 ms |
コード長 | 1,070 bytes |
コンパイル時間 | 556 ms |
コンパイル使用メモリ | 65,372 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-10-01 16:07:29 |
合計ジャッジ時間 | 2,322 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 17 |
ソースコード
#include <iostream> #include <vector> #include <set> using namespace std; #define fastcin {\ cin.tie(0);\ ios::sync_with_stdio(false);\ } #define rep(i, a, b) for(int i = a; i < b; i++) #define REP(i, a) for(int i = 0; i < a; i++) #define scan(x) cin >> x #define print(x) cout << x << "\n" bool prime[10001]; int gr[10001]; void makePrimeList (int x) { REP(i, x+1) prime[i] = true; prime[0] = prime[1] = false; rep(i, 2, x+1) if (prime[i]) for (int j = i << 1; j < x+1; j += i) prime[j] = false; } int main() { fastcin; int n; scan(n); makePrimeList(n); gr[0] = gr[1] = gr[2] = gr[3] = 0; rep(i, 4, n+1) { set<int> g; rep(j, 2, i+1) { if (prime[j]) { int next = i - j; if (next < 2) break; g.insert(gr[next]); } } int res = 0; for (auto &s: g) { if (res == s) res++; else break; } gr[i] = res; } if (gr[n]) print("Win"); else print("Lose"); return 0; }