結果

問題 No.1267 Stop and Coin Game
ユーザー iqueue02iqueue02
提出日時 2020-10-24 16:09:52
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 223 ms / 2,000 ms
コード長 855 bytes
コンパイル時間 3,033 ms
コンパイル使用メモリ 202,900 KB
実行使用メモリ 15,668 KB
最終ジャッジ日時 2023-09-28 20:29:40
合計ジャッジ時間 5,091 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,384 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 11 ms
4,652 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 124 ms
15,668 KB
testcase_11 AC 37 ms
6,172 KB
testcase_12 AC 6 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 202 ms
15,432 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 39 ms
9,348 KB
testcase_25 AC 101 ms
8,944 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 4 ms
4,380 KB
testcase_28 AC 3 ms
4,380 KB
testcase_29 AC 2 ms
4,376 KB
testcase_30 AC 71 ms
15,344 KB
testcase_31 AC 3 ms
4,376 KB
testcase_32 AC 10 ms
4,700 KB
testcase_33 AC 36 ms
9,392 KB
testcase_34 AC 97 ms
8,992 KB
testcase_35 AC 71 ms
15,440 KB
testcase_36 AC 2 ms
4,380 KB
testcase_37 AC 22 ms
4,592 KB
testcase_38 AC 223 ms
15,440 KB
testcase_39 AC 11 ms
4,376 KB
testcase_40 AC 3 ms
4,376 KB
testcase_41 AC 11 ms
4,376 KB
testcase_42 AC 2 ms
4,376 KB
testcase_43 AC 23 ms
4,628 KB
testcase_44 AC 71 ms
15,400 KB
testcase_45 AC 2 ms
4,376 KB
testcase_46 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;

int main() {
  int n;
  ll v;
  cin >> n >> v;
  vector<ll> a(n);
  rep(i,n) cin >> a[i];
  vector<ll> sum(1 << n, 0);
  for (int i = 0; i < (1 << n); i++) {
    for ( int j = 0; j < n; j++) if (i & (1 << j)) sum[i] += a[j];
  }
  vector<int> dp(1 << n, -1);
  
  auto dfs = [&](auto& f, int s, int t)->int{
    if (sum[s] > v) return 1;
    if (dp[s] != -1) return dp[s];
    dp[s] = 0;
    for (int i = 0; i < n; i++) {
      if (s & (1 << i)) continue;
      int d = f(f, s | (1 << i), t ^ 1);
      dp[s] |= !d;
    }
    return dp[s];
  };

  if (sum[(1 << n)-1] <= v) {
    cout << "Draw" << endl;
  } else {
    cout << (dfs(dfs, 0, 0) ? "First" : "Second") << endl;
  }
  return 0;
}
0