結果

問題 No.1267 Stop and Coin Game
ユーザー stoqstoq
提出日時 2020-10-13 03:36:09
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 86 ms / 2,000 ms
コード長 862 bytes
コンパイル時間 1,690 ms
コンパイル使用メモリ 199,180 KB
実行使用メモリ 23,996 KB
最終ジャッジ日時 2023-09-28 00:23:23
合計ジャッジ時間 3,874 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,276 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
5,348 KB
testcase_03 AC 1 ms
5,268 KB
testcase_04 AC 1 ms
5,284 KB
testcase_05 AC 2 ms
5,504 KB
testcase_06 AC 1 ms
5,284 KB
testcase_07 AC 1 ms
5,352 KB
testcase_08 AC 9 ms
6,300 KB
testcase_09 AC 1 ms
5,412 KB
testcase_10 AC 80 ms
23,688 KB
testcase_11 AC 20 ms
11,744 KB
testcase_12 AC 4 ms
5,584 KB
testcase_13 AC 1 ms
5,340 KB
testcase_14 AC 1 ms
5,268 KB
testcase_15 AC 2 ms
5,544 KB
testcase_16 AC 86 ms
23,760 KB
testcase_17 AC 2 ms
5,404 KB
testcase_18 AC 2 ms
5,572 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 2 ms
5,540 KB
testcase_21 AC 1 ms
5,288 KB
testcase_22 AC 2 ms
5,384 KB
testcase_23 AC 2 ms
5,328 KB
testcase_24 AC 34 ms
15,528 KB
testcase_25 AC 55 ms
15,568 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 4 ms
5,604 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 1 ms
5,596 KB
testcase_30 AC 70 ms
23,996 KB
testcase_31 AC 3 ms
5,416 KB
testcase_32 AC 9 ms
6,444 KB
testcase_33 AC 35 ms
15,508 KB
testcase_34 AC 51 ms
15,580 KB
testcase_35 AC 65 ms
23,688 KB
testcase_36 AC 1 ms
4,376 KB
testcase_37 AC 13 ms
6,368 KB
testcase_38 AC 73 ms
23,748 KB
testcase_39 AC 7 ms
5,924 KB
testcase_40 AC 1 ms
4,376 KB
testcase_41 AC 6 ms
6,048 KB
testcase_42 AC 1 ms
4,380 KB
testcase_43 AC 9 ms
6,356 KB
testcase_44 AC 5 ms
13,456 KB
testcase_45 AC 1 ms
4,376 KB
testcase_46 AC 2 ms
5,272 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int n;
ll V, a[20];
ll sum[1 << 22] = {};
int dp[1 << 22][2];

// turn(先手or後手)の必勝か
bool f(int msk, int turn)
{
  if (sum[msk] > V)
    return 1;
  assert(msk != (1 << n) - 1);
  if (dp[msk][turn] != -1)
    return dp[msk][turn];
  rep(i, n)
  {
    if (msk & (1 << i))
      continue;
    if (!f(msk | (1 << i), !turn))
      return dp[msk][turn] = 1;
  }
  return dp[msk][turn] = 0;
}

int main()
{
  cin >> n >> V;
  rep(i, 1 << n) rep(j, 2) dp[i][j] = -1;
  rep(i, n) cin >> a[i];
  if (accumulate(a, a + n, 0LL) <= V)
  {
    cout << "Draw\n";
    return 0;
  }
  rep(msk, 1 << n)
  {
    rep(i, n)
    {
      if (msk & (1 << i))
        sum[msk] += a[i];
    }
  }
  cout << (f(0, 0) ? "First\n" : "Second\n");
}
0