結果
| 問題 |
No.1267 Stop and Coin Game
|
| コンテスト | |
| ユーザー |
Nachia
|
| 提出日時 | 2020-10-23 23:02:13 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 138 ms / 2,000 ms |
| コード長 | 827 bytes |
| コンパイル時間 | 1,573 ms |
| コンパイル使用メモリ | 166,556 KB |
| 実行使用メモリ | 15,744 KB |
| 最終ジャッジ日時 | 2024-07-21 12:12:26 |
| 合計ジャッジ時間 | 3,685 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 43 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
#define rep(i,n) for(int i=0; i<(n); i++)
int N;
LL V;
LL A[20];
LL W[1 << 20];
int memo[1 << 20];
int dp(int X) {
if (memo[X] != -1) return memo[X];
memo[X] = 0;
rep(d, N) {
if (!((1 << d) & X)) continue;
int nx = X - (1 << d);
if (W[nx] < 0) continue;
if (dp(nx) == 0) memo[X] = 1;
}
return memo[X];
}
int main() {
cin >> N;
cin >> V;
rep(i, N) cin >> A[i];
W[0] = V;
rep(d, 20) rep(i, 1 << d) {
W[i + (1 << d)] = W[i];
W[i] -= A[d];
}
if (W[0] >= 0) { cout << "Draw" << endl; return 0; }
rep(i, 1 << N) memo[i] = -1;
if (dp((1 << N) - 1)) cout << "First" << endl;
else cout << "Second" << endl;
return 0;
}
Nachia