結果
問題 |
No.2844 Birthday Party Decoration
|
ユーザー |
![]() |
提出日時 | 2024-08-23 21:15:29 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 11 ms / 2,000 ms |
コード長 | 1,007 bytes |
コンパイル時間 | 3,891 ms |
コンパイル使用メモリ | 250,848 KB |
最終ジャッジ日時 | 2025-02-23 23:27:25 |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 4 |
ソースコード
#include <stdio.h> #include <bits/stdc++.h> #include <atcoder/all> using namespace atcoder; using mint = modint998244353; using namespace std; #define rep(i,n) for (int i = 0; i < (n); ++i) #define Inf32 1000000001 #define Inf64 1000000000000000001 int main(){ int _t; cin>>_t; rep(_,_t){ long long n,x; cin>>n>>x; long long f = 0; rep(i,n){ int a; cin>>a; f |= 1LL<<a; } long long ox = x; rep(i,60){ if((x>>i)&1){ f &= ~(1LL<<i); } } if(f==0){ cout<<0<<endl; continue; } long long msb = 0; rep(i,60){ if((f>>i)&1)msb = 1LL<<i; } long long ans = Inf64; if(ox>=msb){ /*long long t = ox; rep(i,60){ if((1LL<<i)<=msb){ t |= 1LL<<i; } else{ if((t>>i)&1){ t ^= 1LL<<i; break; } } } ans = min(ans,abs(t-ox));*/ } rep(i,60){ if((1LL<<i)>=msb){ x &= ~(1LL<<i); } } ans = min(ans,abs(msb-x)); if(msb<=ox){ ans = min(ans,x+1); } cout<<ans*2<<endl; } return 0; }