結果
問題 |
No.1267 Stop and Coin Game
|
ユーザー |
![]() |
提出日時 | 2020-10-27 16:18:27 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 99 ms / 2,000 ms |
コード長 | 783 bytes |
コンパイル時間 | 2,090 ms |
コンパイル使用メモリ | 198,412 KB |
最終ジャッジ日時 | 2025-01-15 16:01:06 |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 43 |
ソースコード
#include <bits/stdc++.h> #define rep(i, n) for(int i = 0; i < (n); ++i) using namespace std; int main() { int n; long long v; cin >> n >> v; vector<long long> a(n); for(auto &e : a) cin >> e; vector<long long> c(1 << n); rep(s, 1 << n) rep(i, n) { if(s & (1 << i)) c[s] += a[i]; } vector<int> memo(1 << n, -1); auto f = [&](auto &&f, int s) -> int { if(memo[s] != -1) return memo[s]; bitset<22> bs(s); int p = bs.count() % 2; if(c[s] > v) return memo[s] = p ^ 1; rep(i, n) { if(!bs[i] && f(f, s | (1 << i)) != p) return memo[s] = p ^ 1; } return memo[s] = p; }; cout << (c[(1 << n) - 1] <= v ? "Draw" : f(f, 0) ? "First" : "Second") << '\n'; return 0; }