結果

問題 No.1267 Stop and Coin Game
ユーザー simansiman
提出日時 2021-09-24 19:01:10
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 104 ms / 2,000 ms
コード長 1,031 bytes
コンパイル時間 941 ms
コンパイル使用メモリ 104,108 KB
実行使用メモリ 7,672 KB
最終ジャッジ日時 2023-09-18 20:18:16
合計ジャッジ時間 2,665 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
7,644 KB
testcase_01 AC 4 ms
7,600 KB
testcase_02 AC 4 ms
7,516 KB
testcase_03 AC 4 ms
7,608 KB
testcase_04 AC 4 ms
7,588 KB
testcase_05 AC 3 ms
7,600 KB
testcase_06 AC 4 ms
7,616 KB
testcase_07 AC 4 ms
7,612 KB
testcase_08 AC 4 ms
7,556 KB
testcase_09 AC 4 ms
7,544 KB
testcase_10 AC 44 ms
7,556 KB
testcase_11 AC 21 ms
7,508 KB
testcase_12 AC 7 ms
7,612 KB
testcase_13 AC 3 ms
7,560 KB
testcase_14 AC 3 ms
7,588 KB
testcase_15 AC 4 ms
7,604 KB
testcase_16 AC 90 ms
7,620 KB
testcase_17 AC 3 ms
7,564 KB
testcase_18 AC 4 ms
7,552 KB
testcase_19 AC 4 ms
7,600 KB
testcase_20 AC 4 ms
7,628 KB
testcase_21 AC 3 ms
7,612 KB
testcase_22 AC 4 ms
7,560 KB
testcase_23 AC 4 ms
7,588 KB
testcase_24 AC 6 ms
7,564 KB
testcase_25 AC 70 ms
7,612 KB
testcase_26 AC 4 ms
7,588 KB
testcase_27 AC 4 ms
7,608 KB
testcase_28 AC 4 ms
7,556 KB
testcase_29 AC 4 ms
7,600 KB
testcase_30 AC 4 ms
7,596 KB
testcase_31 AC 4 ms
7,568 KB
testcase_32 AC 4 ms
7,584 KB
testcase_33 AC 4 ms
7,568 KB
testcase_34 AC 53 ms
7,628 KB
testcase_35 AC 4 ms
7,592 KB
testcase_36 AC 4 ms
7,504 KB
testcase_37 AC 17 ms
7,612 KB
testcase_38 AC 104 ms
7,624 KB
testcase_39 AC 10 ms
7,600 KB
testcase_40 AC 3 ms
7,604 KB
testcase_41 AC 10 ms
7,672 KB
testcase_42 AC 4 ms
7,548 KB
testcase_43 AC 18 ms
7,644 KB
testcase_44 AC 4 ms
7,552 KB
testcase_45 AC 3 ms
7,512 KB
testcase_46 AC 4 ms
7,588 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cassert>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <limits.h>
#include <map>
#include <queue>
#include <set>
#include <string.h>
#include <vector>

using namespace std;
typedef long long ll;

const int MAX_N = 20;

int memo[1 << 20];
ll A[MAX_N];
ll N, V;

int dfs(int n, ll sum, int mask) {
  if (sum > V) {
    return n % 2 == 0;
  }
  if (memo[mask] != -1) return memo[mask];

  int res = n % 2;
  for (int i = 0; i < N; ++i) {
    if (mask >> i & 1) continue;

    int nmask = mask | (1 << i);
    if (n % 2 == 1) {
      res &= dfs(n + 1, sum + A[i], nmask);
    } else {
      res |= dfs(n + 1, sum + A[i], nmask);
    }
  }

  return memo[mask] = res;
}

int main() {
  memset(memo, -1, sizeof(memo));
  cin >> N >> V;

  ll sum = 0;
  for (int i = 0; i < N; ++i) {
    cin >> A[i];
    sum += A[i];
  }

  if (sum <= V) {
    cout << "Draw" << endl;
  } else  if (dfs(0, 0, 0)) {
    cout << "First" << endl;
  } else {
    cout << "Second" << endl;
  }

  return 0;
}
0