結果

問題 No.2844 Birthday Party Decoration
ユーザー eve__fuyukieve__fuyuki
提出日時 2024-08-23 21:41:47
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 745 bytes
コンパイル時間 2,431 ms
コンパイル使用メモリ 203,956 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-08-23 21:41:50
合計ジャッジ時間 2,582 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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

void fast_io() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
}

void solve() {
	int n;
	long long x;
	cin >> n >> x;
	vector<int> c;
	bool erase_flg = false;
	for (int i = 0; i < n; i++) {
		int a;
		cin >> a;
		if (x & (1LL << a)) {
			erase_flg = true;
			x ^= (1LL << a);
			continue;
		}
		c.push_back(a);
	}
	if (c.empty()) {
		cout << 0 << endl;
		return;
	}
	for (int i = c.back() + 1; i <= 60; i++) {
		if (x & (1LL << i)) {
			x ^= (1LL << i);
		}
	}
	long long ans = (1LL << c.back());
	if (erase_flg) {
		cout << min(2 * (x + 1), 2 * (ans - x)) << endl;
	} else {
		cout << 2 * (ans - x) << endl;
	}
}
int main() {
	fast_io();
	int t;
	cin >> t;
	for (; t--;) {
		solve();
	}
}
0