結果

問題 No.2844 Birthday Party Decoration
コンテスト
ユーザー Shirotsume
提出日時 2024-08-23 22:26:31
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 56 ms / 2,000 ms
コード長 759 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 252 ms
コンパイル使用メモリ 85,712 KB
実行使用メモリ 78,720 KB
最終ジャッジ日時 2026-04-03 22:01:24
合計ジャッジ時間 1,005 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge5_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 4
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

from math import gcd
import sys, time, random
from collections import deque, Counter, defaultdict
def debug(*x):print('debug:',*x, file=sys.stderr)
input = lambda: sys.stdin.readline().rstrip()
ii = lambda: int(input())
mi = lambda: map(int, input().split())
li = lambda: list(mi())
inf = 2 ** 61 - 1

def solve():
    n, x = mi()
    c = li()
    maxc = -1
    for i in range(n):
        if not (1 & (x >> c[i])):
            maxc = max(maxc, c[i])
    if maxc == -1:
        print(0)
        return
    else:
        cost = inf
        if x > (1 << (maxc + 1)):
            cost = (x % (1 << (maxc + 1)) + 1)
        cost = min(cost, (x | ((1 << (maxc + 1)) - 1)) - (1 << maxc) + 1 - x)
        print(2 * cost)
            
for _ in range(ii()):
    solve()
0