結果
| 問題 |
No.2844 Birthday Party Decoration
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-08-23 23:27:38 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 120 ms / 2,000 ms |
| コード長 | 968 bytes |
| コンパイル時間 | 413 ms |
| コンパイル使用メモリ | 82,160 KB |
| 実行使用メモリ | 77,316 KB |
| 最終ジャッジ日時 | 2024-08-23 23:27:40 |
| 合計ジャッジ時間 | 1,399 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 4 |
ソースコード
import sys
input = sys.stdin.readline
def solve():
n,x = map(int,input().split())
c = list(map(int,input().split()))
ans = float('INF')
l = []
for i in c:
if (x >> i) & 1 == 1:
continue
y = x
y += 1<<i
for j in range(i):
if (y >> j) & 1 == 1:
y -= 1<<j
z = x
z -= 1<<i
if z < 0:
z = -10**18
else:
for j in range(i):
if (z >> j) & 1 == 0:
z += 1<<j
l.append([z,y])
#print(l)
for i in range(len(l)+1):
if i == len(l):
z = x
else:
z = l[i][0]
ma = x
for j in range(len(l)):
y = l[j][1]
if z <= y <= x or z <= l[j][0] <= x:
pass
else:
ma = max(ma,y)
ans = min(ans,(ma-z)*2)
print(ans)
for i in range(int(input())):
solve()