結果
問題 |
No.1267 Stop and Coin Game
|
ユーザー |
![]() |
提出日時 | 2020-10-23 23:10:33 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 752 ms / 2,000 ms |
コード長 | 1,668 bytes |
コンパイル時間 | 2,428 ms |
コンパイル使用メモリ | 200,892 KB |
最終ジャッジ日時 | 2025-01-15 13:56:11 |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 43 |
ソースコード
#include <bits/stdc++.h> #define rep(i,n) for (int i = 0; i < (n); ++i) #define rrep(i,n) for (int i = (n)-1; i >= 0; --i) #define chmax(a, b) a = max(a, b) #define chmin(a, b) a = min(a, b) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() using namespace std; using ll = long long; using P = pair<int,int>; using VI = vector<int>; using VVI = vector<VI>; std::vector<int> compute_grundy(std::vector<std::vector<int>>& to) { int sz = to.size(); std::vector<int> vsorted(sz); std::vector<int> indeg(sz); for(int i = 0; i < sz; i++) for(int j: to[i]) indeg[j]++; std::vector<int> avail; for(int i = 0; i < sz; i++) if (indeg[i] == 0) avail.push_back(i); int nxt_idx = 0; while(!avail.empty()) { int u = avail.back(); avail.pop_back(); vsorted[nxt_idx++] = u; for(int v: to[u]) if (--indeg[v] == 0) avail.push_back(v); } std::vector<int> grundy(sz), used(sz, -1); for(int i = sz - 1; i >= 0; i--) { int u = vsorted[i]; for(int v: to[u]) used[grundy[v]] = u; int g = 0; while(used[g] == u) g++; grundy[u] = g; } return grundy; } int main() { int n; ll v; cin >> n >> v; vector<ll> a(n); ll tot = 0; rep(i, n) { cin >> a[i]; tot += a[i]; } if (tot <= v) { cout << "Draw" << endl; return 0; } int smx = 1 << n; VVI to(smx); rep(s, smx) { ll now = 0; rep(i, n) if (s >> i & 1) now += a[i]; rep(i, n) if ((s >> i & 1) == 0 && now + a[i] <= v) { to[s].push_back(s | 1 << i); } } auto g = compute_grundy(to); if (g[0]) cout << "First" << endl; else cout << "Second" << endl; }