結果
| 問題 |
No.1267 Stop and Coin Game
|
| コンテスト | |
| ユーザー |
mencotton
|
| 提出日時 | 2020-11-02 15:42:14 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 126 ms / 2,000 ms |
| コード長 | 954 bytes |
| コンパイル時間 | 679 ms |
| コンパイル使用メモリ | 74,804 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-22 06:18:03 |
| 合計ジャッジ時間 | 2,870 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 43 |
ソースコード
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using ll = long long;
ll n, v;
vector<ll> a;
int main() {
cin >> n >> v;
a.resize(n);
for (int i = 0; i < n; i++)cin >> a[i];
ll sum = 0;
for (int i = 0; i < n; i++)sum += a[i];
if (sum <= v) {
cout << "Draw" << endl;
return 0;
}
vector<bool> dp(1 << n);
for (int used = (1 << n) - 1; used >= 0; used--) {
ll remain = v;
for (int i = 0; i < n; i++) {
if (used & (1 << i))remain -= a[i];
}
if (remain <= 0)continue;
bool canWin = false;
for (int i = 0; i < n; i++) {
if ((used & 1 << i) == 0 && remain >= a[i]) {
used ^= 1 << i;
if (!dp[used])canWin = true;
used ^= 1 << i;
}
}
dp[used] = canWin;
}
cout << (dp[0] ? "First" : "Second") << endl;
return 0;
}
mencotton