結果

問題 No.1267 Stop and Coin Game
ユーザー simansiman
提出日時 2021-09-24 18:48:03
言語 C++17(clang)
(17.0.6 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 940 bytes
コンパイル時間 1,128 ms
コンパイル使用メモリ 140,924 KB
実行使用メモリ 7,624 KB
最終ジャッジ日時 2024-07-05 09:46:17
合計ジャッジ時間 2,758 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 25 WA * 18
権限があれば一括ダウンロードができます

ソースコード

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 > N) {
    return n % 2 == 0;
  }
  if (memo[mask] != -1) return memo[mask];

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

    int nmask = mask | (1 << i);
    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