結果
問題 | No.1267 Stop and Coin Game |
ユーザー |
![]() |
提出日時 | 2020-10-24 16:09:52 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 176 ms / 2,000 ms |
コード長 | 855 bytes |
コンパイル時間 | 2,114 ms |
コンパイル使用メモリ | 197,960 KB |
最終ジャッジ日時 | 2025-01-15 15:06:34 |
ジャッジサーバーID (参考情報) |
judge3 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 43 |
ソースコード
#include <bits/stdc++.h>using namespace std;#define rep(i,n) for(int i = 0; i < (n); i++)typedef long long ll;typedef long double ld;typedef pair<int,int> P;int main() {int n;ll v;cin >> n >> v;vector<ll> a(n);rep(i,n) cin >> a[i];vector<ll> sum(1 << n, 0);for (int i = 0; i < (1 << n); i++) {for ( int j = 0; j < n; j++) if (i & (1 << j)) sum[i] += a[j];}vector<int> dp(1 << n, -1);auto dfs = [&](auto& f, int s, int t)->int{if (sum[s] > v) return 1;if (dp[s] != -1) return dp[s];dp[s] = 0;for (int i = 0; i < n; i++) {if (s & (1 << i)) continue;int d = f(f, s | (1 << i), t ^ 1);dp[s] |= !d;}return dp[s];};if (sum[(1 << n)-1] <= v) {cout << "Draw" << endl;} else {cout << (dfs(dfs, 0, 0) ? "First" : "Second") << endl;}return 0;}