結果

問題 No.2844 Birthday Party Decoration
ユーザー HIcoderHIcoder
提出日時 2024-09-08 22:45:04
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 10 ms / 2,000 ms
コード長 1,246 bytes
コンパイル時間 1,445 ms
コンパイル使用メモリ 123,992 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-09-08 22:45:07
合計ジャッジ時間 2,028 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 9 ms
6,940 KB
testcase_02 AC 10 ms
6,940 KB
testcase_03 AC 9 ms
6,940 KB
testcase_04 AC 10 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
    }
}
0