結果

問題 No.1267 Stop and Coin Game
ユーザー ntuda
提出日時 2025-02-03 21:57:47
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 664 bytes
コンパイル時間 516 ms
コンパイル使用メモリ 82,884 KB
実行使用メモリ 134,344 KB
最終ジャッジ日時 2025-02-03 21:58:00
合計ジャッジ時間 8,775 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 26 WA * 17
権限があれば一括ダウンロードができます

ソースコード

diff #

N,V = map(int,input().split())
A = list(map(int,input().split()))
A.sort(reverse = True)
if sum(A) <= V:
    print("Draw")
    exit()

allb = (1<<N)-1
X = [0] * (allb + 1)
for i in range(allb + 1):
    x = i ^ allb
    t1 = V
    for j in range(N):
        if x & (1<<j):
            t1 -= A[j]
    X[i] = t1

from functools import lru_cache
@lru_cache(maxsize=1050000)
def f(x):
    #if X[x] < 0:
    #    return True
    for i in range(N):
        if x & (1<<i):
            if X[x] - A[i] < 0:
                return False
            if not(f(x ^ (1<<i))):
                return True
    return False

if f(allb):
    print("First")
else:
    print("Second")
0