結果

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

ソースコード

diff #

#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <tuple>
#include <vector>
using namespace std;
using ll = int64_t;
#define rep(i, j, n) for (int i = j; i < (n); ++i)
#define rrep(i, j, n) for (int i = (n)-1; j <= i; --i)

int main() {
  ll n, v;
  cin >> n >> v;
  vector<ll> a(n);
  ll s = 0;
  rep(i, 0, n) {
    cin >> a[i];
    s += a[i];
  }

  if (s <= v) {
    cout << "Draw" << endl;
    return 0;
  }
  sort(a.begin(), a.end());
  // どれをとったかの状態を持ってしたからdp?
  // 下位集合が全て負け状態なら価値状態
  vector<bool> dp(1 << n);
  rep(i, 0, n) rep(S, 0, 1 << n) if (S & (1 << i)) dp[S] =
    dp[S] | !dp[S ^ 1 << i];
  unordered_map<ll, bool> mp;
  rep(S, 1, 1 << n) {
    ll t = 0;
    rep(i, 0, n) if (S >> i & 1) t += a[i];
    mp[t] = dp[S];
  }

  if (mp[v])
    cout << "First" << endl;
  else
    cout << "Second" << endl;

  return 0;
}
0