結果
問題 |
No.1267 Stop and Coin Game
|
ユーザー |
![]() |
提出日時 | 2020-10-27 16:31:18 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 194 ms / 2,000 ms |
コード長 | 740 bytes |
コンパイル時間 | 2,735 ms |
コンパイル使用メモリ | 197,508 KB |
最終ジャッジ日時 | 2025-01-15 16:01:17 |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
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 p) -> int { if(memo[s] != -1) return memo[s]; if(c[s] > v) return memo[s] = 1; rep(i, n) if(!(s & (1 << i))) { if(!f(f, s | (1 << i), p ^ 1)) return memo[s] = 1; } return memo[s] = 0; }; cout << (c[(1 << n) - 1] <= v ? "Draw" : f(f, 0, 0) ? "First" : "Second") << '\n'; return 0; }