結果
| 問題 |
No.1267 Stop and Coin Game
|
| コンテスト | |
| ユーザー |
lam6er
|
| 提出日時 | 2025-03-31 17:34:58 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 1,629 ms / 2,000 ms |
| コード長 | 1,117 bytes |
| コンパイル時間 | 219 ms |
| コンパイル使用メモリ | 82,748 KB |
| 実行使用メモリ | 183,660 KB |
| 最終ジャッジ日時 | 2025-03-31 17:35:59 |
| 合計ジャッジ時間 | 16,106 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 43 |
ソースコード
n, v = map(int, input().split())
a = list(map(int, input().split()))
sum_total = sum(a)
if sum_total <= v:
print("Draw")
else:
n_masks = 1 << n
sum_mask = [0] * n_masks
for i in range(n):
bit = 1 << i
for mask in range(n_masks):
if not (mask & bit):
sum_mask[mask | bit] += a[i]
# Generate all masks in order of descending number of bits
masks = sorted(range(n_masks), key=lambda x: bin(x).count('1'), reverse=True)
dp = [False] * n_masks
for mask in masks:
current_sum = sum_mask[mask]
available = []
for i in range(n):
if not (mask & (1 << i)):
if current_sum + a[i] <= v:
available.append(i)
if not available:
dp[mask] = False
else:
can_win = False
for i in available:
next_mask = mask | (1 << i)
if not dp[next_mask]:
can_win = True
break
dp[mask] = can_win
print("First" if dp[0] else "Second")
lam6er