結果

問題 No.2844 Birthday Party Decoration
ユーザー t98slidert98slider
提出日時 2024-08-23 21:57:40
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 772 bytes
コンパイル時間 1,979 ms
コンパイル使用メモリ 202,620 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-08-23 21:57:43
合計ジャッジ時間 2,235 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int T;
    cin >> T;
    while(T--){
        ll n, x, S = 0;
        cin >> n >> x;
        ll ans = 0;
        for(int i = 0; i < n; i++){
            int v;
            cin >> v;
            S |= 1ll << v;
        }
        S &= ~x;
        if(S == 0){
            cout << 0 << '\n';
            continue;
        }
        ll T = 1ll << __lg(S);
        ans = T - (x & (T - 1));
        if(S <= x){
            for(int i = 0; i < 60; i++){
                if(S >> i & 1) continue;
                if(S + (1ll << i) <= x) S += 1ll << i;
            }
            ans = min(ans, x - S);
        }
        cout << 2 * ans << '\n';
    }
}
0