結果
| 問題 |
No.1267 Stop and Coin Game
|
| コンテスト | |
| ユーザー |
trineutron
|
| 提出日時 | 2020-10-23 22:24:03 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 122 ms / 2,000 ms |
| コード長 | 1,050 bytes |
| コンパイル時間 | 2,347 ms |
| コンパイル使用メモリ | 197,392 KB |
| 最終ジャッジ日時 | 2025-01-15 13:22:14 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 43 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
int main() {
int64_t n, v;
cin >> n >> v;
vector<int64_t> a(n);
for (int i = 0; i < n; i++) {
cin >> a.at(i);
}
const int64_t s = accumulate(a.begin(), a.end(), 0L);
if (s <= v) {
puts("Draw");
return 0;
}
const int t = 1 << n;
vector<bool> ok(t);
for (int i = 0; i < t; i++) {
int64_t x = 0;
for (int j = 0; j < n; j++) {
if (i >> j & 1) {
x += a.at(j);
}
}
ok.at(i) = x <= v;
}
vector<bool> win(t);
for (int i = t - 1; i >= 0; i--) {
if (not ok.at(i)) {
win.at(i) = true;
continue;
}
for (int j = 0; j < n; j++) {
if (i >> j & 1) continue;
int next = i + (1 << j);
if (not win.at(next)) {
win.at(i) = true;
break;
}
}
}
if (win.at(0)) {
puts("First");
} else {
puts("Second");
}
}
trineutron