結果
| 問題 |
No.2844 Birthday Party Decoration
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-09-08 22:45:04 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 11 ms / 2,000 ms |
| コード長 | 1,246 bytes |
| コンパイル時間 | 1,278 ms |
| コンパイル使用メモリ | 119,288 KB |
| 最終ジャッジ日時 | 2025-02-24 06:02:47 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 4 |
ソースコード
#include<iostream>
#include<string>
#include<queue>
#include<vector>
#include<cassert>
#include<random>
#include<set>
#include<map>
#include<cassert>
#include<unordered_map>
#include<bitset>
#include<numeric>
#include<algorithm>
using namespace std;
typedef long long ll;
const int inf=1<<30;
const ll INF=1LL<<62;
typedef pair<int,ll> P;
typedef pair<int,P> PP;
const ll MOD=998244353;
ll solve(){
int N;
ll X;
cin>>N>>X;
vector<int> c(N);
for(int i=0;i<N;i++) cin>>c[i];
sort(c.begin(),c.end());
reverse(c.begin(),c.end());
//大きい方から見ていく
int t=-1;
for(ll v:c){
if((X>>v)&1) continue;
else{
t=v;
break;
}
}
if(t==-1){
return 0;
}
ll ans=INF;
{
ll v=(X/(1LL<<t)+1)*(1LL<<t);
ans=min(ans,abs(v-X));
}
{
ll v=X/(1LL<<t);
if(v>0){
v*=(1LL<<t);
v-=1;
ans=min(ans,abs(v-X));
}
}
//往復を考慮して2倍する
return ans*2;
}
int main(){
int T;
cin>>T;
vector<ll> ans(T);
for(int t=0;t<T;t++){
ans[t]=solve();
}
for(int t=0;t<T;t++){
cout<<ans[t]<<endl;
}
}