結果

問題 No.1267 Stop and Coin Game
ユーザー kawara_y_kyopro
提出日時 2020-10-24 00:07:09
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 75 ms / 2,000 ms
コード長 1,792 bytes
コンパイル時間 1,406 ms
コンパイル使用メモリ 121,252 KB
最終ジャッジ日時 2025-01-15 14:32:02
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 43
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <bitset>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define ALL(v) v.begin(),v.end()
template < class T > inline bool chmax(T& a, T b) {if (a < b) { a=b; return true; } return false; }
template < class T > inline bool chmin(T& a, T b) {if (a > b) { a=b; return true; } return false; }
#define DEBUG_VLL(vec) for(int sz=0;sz<int(vec.size());sz++) std::cerr<<vec[sz]<<(sz==int(vec.size())-1?'\n':' ');

const long long MOD = 1000000007;
const long long HIGHINF = (long long)1e18;
const int INF = (int)1e9;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; ll v; cin >> n >> v;
    vll a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    if (accumulate(ALL(a), 0LL) <= v) {
        cout << "Draw\n";
        return 0;
    }

    V<int> dp(1 << n, -1);
    auto memo = [&](auto && self, int state, ll sum) -> bool {
        if (dp[state] != -1) return dp[state];
        if (sum > v) return dp[state] = 1;
        int tmp = 1;
        for (int i = 0; i < n; i++) {
            if (state >> i & 1) continue;
            tmp = tmp & self(self, state | (1 << i), sum + a[i]);
        }
        return (dp[state] = tmp ^ 1);
    };

    if (memo(memo, 0, 0)) cout << "First\n";
    else cout << "Second\n";
    return 0;
}
0