結果

問題 No.1267 Stop and Coin Game
ユーザー 👑 NachiaNachia
提出日時 2020-10-23 23:02:13
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 150 ms / 2,000 ms
コード長 827 bytes
コンパイル時間 1,609 ms
コンパイル使用メモリ 164,156 KB
実行使用メモリ 15,700 KB
最終ジャッジ日時 2023-09-28 17:33:40
合計ジャッジ時間 4,005 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
11,744 KB
testcase_01 AC 5 ms
11,524 KB
testcase_02 AC 5 ms
11,568 KB
testcase_03 AC 5 ms
11,756 KB
testcase_04 AC 5 ms
11,512 KB
testcase_05 AC 5 ms
11,596 KB
testcase_06 AC 6 ms
11,596 KB
testcase_07 AC 5 ms
11,520 KB
testcase_08 AC 6 ms
12,148 KB
testcase_09 AC 5 ms
11,512 KB
testcase_10 AC 58 ms
15,608 KB
testcase_11 AC 24 ms
12,536 KB
testcase_12 AC 8 ms
11,696 KB
testcase_13 AC 5 ms
11,568 KB
testcase_14 AC 5 ms
11,520 KB
testcase_15 AC 5 ms
11,572 KB
testcase_16 AC 127 ms
15,652 KB
testcase_17 AC 5 ms
11,516 KB
testcase_18 AC 6 ms
11,600 KB
testcase_19 AC 5 ms
11,512 KB
testcase_20 AC 5 ms
11,564 KB
testcase_21 AC 5 ms
11,516 KB
testcase_22 AC 5 ms
11,604 KB
testcase_23 AC 5 ms
11,648 KB
testcase_24 AC 10 ms
15,600 KB
testcase_25 AC 87 ms
15,608 KB
testcase_26 AC 5 ms
11,520 KB
testcase_27 AC 5 ms
11,648 KB
testcase_28 AC 6 ms
11,748 KB
testcase_29 AC 5 ms
11,568 KB
testcase_30 AC 8 ms
15,604 KB
testcase_31 AC 6 ms
11,552 KB
testcase_32 AC 6 ms
12,208 KB
testcase_33 AC 7 ms
15,600 KB
testcase_34 AC 64 ms
15,700 KB
testcase_35 AC 8 ms
15,652 KB
testcase_36 AC 6 ms
11,752 KB
testcase_37 AC 19 ms
12,028 KB
testcase_38 AC 150 ms
15,648 KB
testcase_39 AC 11 ms
11,824 KB
testcase_40 AC 5 ms
11,616 KB
testcase_41 AC 12 ms
11,844 KB
testcase_42 AC 5 ms
11,568 KB
testcase_43 AC 16 ms
12,028 KB
testcase_44 AC 5 ms
11,560 KB
testcase_45 AC 5 ms
11,696 KB
testcase_46 AC 6 ms
11,512 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0