結果
問題 | No.1267 Stop and Coin Game |
ユーザー |
|
提出日時 | 2020-10-23 22:41:33 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 103 ms / 2,000 ms |
コード長 | 937 bytes |
コンパイル時間 | 1,674 ms |
コンパイル使用メモリ | 169,532 KB |
実行使用メモリ | 7,376 KB |
最終ジャッジ日時 | 2024-07-21 11:34:35 |
合計ジャッジ時間 | 3,774 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 43 |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; constexpr char newl = '\n'; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int n; ll v; cin >> n >> v; vector<ll> a(n); ll asum = 0; for (int i = 0; i < n; i++) { cin >> a[i]; asum += a[i]; } if (asum <= v) { cout << "Draw\n"; return 0; } vector<int> dp(1 << 20, false); for (int i = (1 << n) - 1; i >= 0; --i) { ll sum = 0; for (int j = 0; j < n; j++) { if (i >> j & 1) sum += a[j]; } if (sum > v) { dp[i] = true; continue; } for (int j = 0; j < n; j++) { if (i >> j & 1) continue; if (!dp[i | (1 << j)]) { dp[i] = true; break; } } } cout << (dp[0] ? "First" : "Second") << newl; return 0; }