結果

問題 No.1267 Stop and Coin Game
ユーザー roaris
提出日時 2020-11-14 14:27:13
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 174 ms / 2,000 ms
コード長 732 bytes
コンパイル時間 3,174 ms
コンパイル使用メモリ 192,564 KB
最終ジャッジ日時 2025-01-16 00:34:22
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 43
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i=0; i<n; i++)
#define pb push_back
#define int long long

int N, V;
int A[22];
int memo[(1<<20)+10];

int rec(int S, int V) {
    if (memo[S]!=0) return memo[S];
    int res = -1;
    for (int i=0; i<N; i++) {
        if (!((S>>i)&1) && V-A[i]>=0) {
            res = max(res, -rec(S|(1<<i), V-A[i]));
        }
    }
    return memo[S] = res;
}

signed main() {
    cin.tie(0); ios::sync_with_stdio(false);
    cin >> N >> V;
    int S = 0;
    rep(i, N) {
        cin >> A[i];
        S += A[i];
    }
    if (S<=V) {
        cout << "Draw" << endl;
        exit(0);
    }
    if (rec(0, V)==1) cout << "First" << endl;
    else cout << "Second" << endl;
}
0