結果

問題 No.1267 Stop and Coin Game
ユーザー SPD_9X2
提出日時 2020-10-23 22:28:15
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,141 ms / 2,000 ms
コード長 885 bytes
コンパイル時間 390 ms
コンパイル使用メモリ 82,128 KB
実行使用メモリ 125,536 KB
最終ジャッジ日時 2024-07-21 11:15:10
合計ジャッジ時間 10,915 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 43
権限があれば一括ダウンロードができます

ソースコード

diff #

"""

ゲームdfs?
2^20

1を勝ち、0を負けとする
1つでも0があったら勝ち

"""

from sys import stdin
import sys
N,V = map(int,stdin.readline().split())
A = list(map(int,stdin.readline().split()))

if sum(A) <= V:
    print ("Draw")
    sys.exit()

ans = [-1] * (2**N)
ans[0] = None
np = [0]
qi = 0

while qi < len(np):
    for j in range(N):
        nex = np[qi] | (1<<j)
        if ans[nex] == -1:
            ans[nex] = None
            np.append(nex)
    qi += 1

np.reverse()


for i in np:

    s = 0
    for j in range(N):
        if (1<<j)&i > 0:
            s += A[j]
    if s > V:
        ans[i] = 1
    else:
        for j in range(N):
            if (1<<j)&i == 0 and ans[(1<<j)|i] == 0:
                ans[i] = 1
                break
        else:
            ans[i] = 0

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