結果

問題 No.1267 Stop and Coin Game
ユーザー tobusakanatobusakana
提出日時 2022-10-23 16:51:13
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 387 ms / 2,000 ms
コード長 906 bytes
コンパイル時間 275 ms
コンパイル使用メモリ 87,196 KB
実行使用メモリ 85,504 KB
最終ジャッジ日時 2023-09-15 02:52:09
合計ジャッジ時間 8,601 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,608 KB
testcase_01 AC 72 ms
71,456 KB
testcase_02 AC 72 ms
71,428 KB
testcase_03 AC 71 ms
71,588 KB
testcase_04 AC 73 ms
71,512 KB
testcase_05 AC 83 ms
76,532 KB
testcase_06 AC 82 ms
76,124 KB
testcase_07 AC 70 ms
71,488 KB
testcase_08 AC 117 ms
78,132 KB
testcase_09 AC 76 ms
76,312 KB
testcase_10 AC 352 ms
85,504 KB
testcase_11 AC 163 ms
79,328 KB
testcase_12 AC 96 ms
76,900 KB
testcase_13 AC 72 ms
71,300 KB
testcase_14 AC 73 ms
71,156 KB
testcase_15 AC 80 ms
76,572 KB
testcase_16 AC 381 ms
85,264 KB
testcase_17 AC 72 ms
71,292 KB
testcase_18 AC 86 ms
76,596 KB
testcase_19 AC 74 ms
71,400 KB
testcase_20 AC 77 ms
76,428 KB
testcase_21 AC 72 ms
71,492 KB
testcase_22 AC 89 ms
76,608 KB
testcase_23 AC 71 ms
71,292 KB
testcase_24 AC 208 ms
81,124 KB
testcase_25 AC 254 ms
81,136 KB
testcase_26 AC 71 ms
71,372 KB
testcase_27 AC 87 ms
76,884 KB
testcase_28 AC 71 ms
71,468 KB
testcase_29 AC 89 ms
76,652 KB
testcase_30 AC 359 ms
85,428 KB
testcase_31 AC 90 ms
76,616 KB
testcase_32 AC 102 ms
77,676 KB
testcase_33 AC 198 ms
81,052 KB
testcase_34 AC 249 ms
81,252 KB
testcase_35 AC 350 ms
85,436 KB
testcase_36 AC 73 ms
71,308 KB
testcase_37 AC 129 ms
78,132 KB
testcase_38 AC 387 ms
85,276 KB
testcase_39 AC 107 ms
77,144 KB
testcase_40 AC 72 ms
71,648 KB
testcase_41 AC 113 ms
77,100 KB
testcase_42 AC 72 ms
71,368 KB
testcase_43 AC 125 ms
77,984 KB
testcase_44 AC 73 ms
71,456 KB
testcase_45 AC 71 ms
71,160 KB
testcase_46 AC 72 ms
71,292 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# Aの合計がV以下であればDraw
# N枚の硬貨のうちどれを使っているかの状態をSとし、
# 負の状態で回ってきたら勝ち
# 正の状態のとき、負けに遷移できるなら勝ち、できないなら負け

import sys
readline = sys.stdin.readline

N,V = map(int,readline().split())
A = list(map(int,readline().split()))
if sum(A) <= V:
  print("Draw")
  exit(0)
  
dp = [False] * (1 << N)
for status in range((1 << N) - 1, -1, -1):
  amt = 0
  for i in range(N):
    if (status >> i) & 1:
      amt += A[i]
  if V - amt < 0: # 勝ちの状態
    dp[status] = True
    continue
  # この状態からコインを新規で選んで負けの状態に遷移できるか
  for target in range(N):
    if (status >> target) & 1:
      continue
    if not dp[status | (1 << target)]:
      dp[status] = True
      break

if dp[0]:
  print("First")
else:
  print("Second")
0