結果

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

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,b,e) for (int i=(int)(b); i<(int)(e); i++)
#define ALL(x) (x).begin(), (x).end()

const double PI = acos(-1);

int n;
long long v;
long long a[20];
int dp[1<<20];

bool dfs(int vis) {
  if (dp[vis] != -1)
    return dp[vis];

  long long acc = 0;
  REP (i, n) if (vis & 1 << i) acc += a[i];
  if (acc > v)
    return dp[vis] = true;

  bool ret = false;
  REP (i, n) {
    if (vis & 1 << i) continue;
    if (!dfs(vis | 1 << i))
      ret = true;
  }
  
  return dp[vis] = ret;
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  cin >> n >> v;
  REP (i, n) cin >> a[i];
  memset(dp, -1, sizeof(dp));
  
  long long sum = 0;
  REP (i, n) sum += a[i];
  if (v >= sum)
    cout << "Draw" << endl;
  else if (dfs(0))
    cout << "First" << endl;
  else
    cout << "Second" << endl;
    
  return 0;
}
0