結果

問題 No.1267 Stop and Coin Game
コンテスト
ユーザー stnkien
提出日時 2020-10-23 23:40:37
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 779 ms / 2,000 ms
コード長 641 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 167 ms
コンパイル使用メモリ 85,420 KB
実行使用メモリ 88,996 KB
最終ジャッジ日時 2026-04-03 04:50:45
合計ジャッジ時間 8,496 ms
ジャッジサーバーID
(参考情報)
judge3_1 / judge5_1
純コード判定待ち
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 43
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

N, V = map(int, input().split())
*A, = map(int, input().split())

if sum(A) <= V:
    print('Draw')
    exit()

dp = [0]*(1<<N)
for bit in range((1<<N)-1, -1, -1):
    tot = 0
    cnt = bin(bit).count('1')
    res = 1 if cnt & 1 else 2
    for i in range(N):
        if bit >> i & 1:
            tot += A[i]
        else:
            nb = bit|(1<<i)
            if cnt & 1:
                if dp[nb] == 2:
                    res = 2
            else:
                if dp[nb] == 1:
                    res = 1
    if tot > V:
        dp[bit] = 2 if cnt & 1 else 1
    else:
        dp[bit] = res
print('First' if dp[0] == 1 else 'Second')
0