結果
| 問題 |
No.2844 Birthday Party Decoration
|
| コンテスト | |
| ユーザー |
titia
|
| 提出日時 | 2024-08-24 01:39:58 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,028 bytes |
| コンパイル時間 | 199 ms |
| コンパイル使用メモリ | 12,672 KB |
| 実行使用メモリ | 10,880 KB |
| 最終ジャッジ日時 | 2024-08-24 01:40:00 |
| 合計ジャッジ時間 | 1,463 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | WA * 4 |
ソースコード
import sys
input = sys.stdin.readline
T=int(input())
for tests in range(T):
N,X=map(int,input().split())
C=list(map(int,input().split()))
A=[]
for c in C:
if (1<<c) & X !=0:
continue
k=2**c
a=(X+k-1)//k
if a%2==0:
a+=1
A.append(a*k-X)
B=[]
for c in C:
if (1<<c) & X !=0:
continue
k=2**c
a=X//k
if a%2==0:
a-=1
if a<0:
B.append(1<<60)
else:
B.append(X-a*k)
#print(A)
#print(B)
if A==[] and B==[]:
print(0)
continue
D=[]
for i in range(len(A)):
D.append((A[i],B[i]))
D.sort()
#print(D)
MAX=[0]*len(D)
MAX[-1]=D[-1][1]
for i in range(len(D)-2,-1,-1):
MAX[i]=max(MAX[i+1],D[i][1])
ANS=min(D[-1][0]*2,MAX[0]*2)
for i in range(len(D)-1):
l=D[i][0]
r=MAX[i+1]
ANS=min(ANS,min(l,r)*2+max(l,r))
print(ANS)
titia