結果

問題 No.1267 Stop and Coin Game
ユーザー tcltk
提出日時 2021-05-18 15:09:43
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,573 ms / 2,000 ms
コード長 996 bytes
コンパイル時間 455 ms
コンパイル使用メモリ 82,348 KB
実行使用メモリ 98,560 KB
最終ジャッジ日時 2024-10-08 15:17:01
合計ジャッジ時間 18,827 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 43
権限があれば一括ダウンロードができます

ソースコード

diff #

#region Header
#!/usr/bin/env python3
# from typing import *

import sys
import io
import math
import collections
import decimal
import itertools
import bisect
import heapq


def input():
    return sys.stdin.readline()[:-1]


# sys.setrecursionlimit(1000000)
#endregion

# _INPUT = """3 5
# 5 1 1
# """
# sys.stdin = io.StringIO(_INPUT)


def main():
    N, V = map(int, input().split())
    A = list(map(int, input().split()))

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

    dp = [None] * (1<<N)
    for s in range(1<<N):
        cap = sum(A[i] for i in range(N) if s & (1<<i))
        dp[s] = (cap <= V)

    for s in reversed(range(1<<N)):
        if dp[s]:
            # 自分が何を選んでも、次に相手は勝つ。ということは、自分は負け
            if any(dp[s | (1<<j)] for j in range(N) if s & (1<<j) == 0):
                dp[s] = False

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

if __name__ == '__main__':
    main()
0