結果
| 問題 |
No.2844 Birthday Party Decoration
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-08-23 22:00:44 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 5 ms / 2,000 ms |
| コード長 | 786 bytes |
| コンパイル時間 | 2,159 ms |
| コンパイル使用メモリ | 192,672 KB |
| 最終ジャッジ日時 | 2025-02-23 23:46:34 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 4 |
ソースコード
#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){
ll d = 1;
for(int i = 0; i < 60; i++){
if(x >> i & 1) d += 1ll << i;
if(((x - d) & S) == S) break;
}
ans = min(ans, d);
}
cout << 2 * ans << '\n';
}
}