結果
問題 |
No.1267 Stop and Coin Game
|
ユーザー |
![]() |
提出日時 | 2020-10-27 19:50:20 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 23 ms / 2,000 ms |
コード長 | 638 bytes |
コンパイル時間 | 1,710 ms |
コンパイル使用メモリ | 196,652 KB |
最終ジャッジ日時 | 2025-01-15 16:03:13 |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 43 |
ソースコード
#include <bits/stdc++.h> 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<int> dp(1 << n, -1); auto f = [&](auto &&f, int s, int p, long long sum) -> int { if(dp[s] != -1) return dp[s]; if(sum > v) return dp[s] = 1; for(int i = 0; i < n; ++i) if(!(s & (1 << i))) { if(!f(f, s | (1 << i), p ^ 1, sum + a[i])) return dp[s] = 1; } return dp[s] = 0; }; cout << (accumulate(a.begin(), a.end(), 0LL) <= v ? "Draw" : f(f, 0, 0, 0) ? "First" : "Second") << '\n'; return 0; }