結果
問題 | No.1267 Stop and Coin Game |
ユーザー |
|
提出日時 | 2022-02-19 16:15:37 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 305 ms / 2,000 ms |
コード長 | 1,011 bytes |
コンパイル時間 | 174 ms |
コンパイル使用メモリ | 82,304 KB |
実行使用メモリ | 92,416 KB |
最終ジャッジ日時 | 2024-06-29 10:27:06 |
合計ジャッジ時間 | 4,838 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 43 |
ソースコード
N,V = map(int,input().split())A = list(map(int,input().split()))S = sum(A)import sysif S <= V:print("Draw")exit()sys.setrecursionlimit(10 ** 8 )dat = [0] * (1 << N)for bit in range(1,1 << N):for i in range(N):mask = 1 << iif bit & mask:dat[bit] = A[i] + dat[bit ^ mask]break"""from functools import lru_cache@lru_cachedef calc(S = 0):#flag = S.count('1')for i in range(N):mask = 1 << iif S & mask:continueif dat[S | mask] > V:continuea = calc(S | mask)if a == False:return Truereturn False"""grundy = [0] * (1 << N)for bit in range((1 << N)-1,-1,-1):flag = Falsefor i in range(N):mask = 1 << iif bit & mask:continueif dat[bit | mask] > V:continueif grundy[bit | mask] == 0:flag = Truebreakif flag:grundy[bit] = 1else:grundy[bit] = 0print('First' if grundy[0] else "Second")