結果
| 問題 | No.3046 White Tiger vs Monster |
| ユーザー |
|
| 提出日時 | 2026-08-22 00:24:17 |
| 言語 | C++23 (gcc 15.2.0 + boost 1.90.0) |
| 結果 |
AC
|
| 実行時間 | 44 ms / 2,000 ms |
| + 158µs | |
| コード長 | 2,036 bytes |
| 記録 | |
| コンパイル時間 | 2,621 ms |
| コンパイル使用メモリ | 338,044 KB |
| 実行使用メモリ | 9,412 KB |
| 最終ジャッジ日時 | 2026-08-22 00:24:33 |
| 合計ジャッジ時間 | 14,367 ms |
|
ジャッジサーバーID (参考情報) |
judge1_0 / judge3_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 80 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ull = unsigned long long;
int msb(ull x) {
return 63 - __builtin_clzll(x);
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N;
ull B;
cin >> N >> B;
vector<ull> A(N);
for (ull& x : A) cin >> x;
const int K = msb(B);
vector<ull> lower;
vector<ull> same;
ull totalXor = 0;
for (ull x : A) {
int k = msb(x);
if (k < K) {
lower.push_back(x);
totalXor ^= x;
} else if (k == K) {
same.push_back(x);
}
}
const int base = (int)lower.size();
// edge[j] の第 l ビットが1
// ⇔ j から l へ直接移動できる
vector<ull> edge(K, 0);
for (ull x : lower) {
int l = msb(x);
for (int j = 0; j < l; ++j) {
if (((x >> j) & 1ULL) == 0) {
edge[j] |= 1ULL << l;
}
}
}
// reach[j]: jから到達可能な最高位ビットの集合
vector<ull> reach(K, 0);
for (int j = K - 1; j >= 0; --j) {
reach[j] = 1ULL << j;
for (int l = j + 1; l < K; ++l) {
if ((edge[j] >> l) & 1ULL) {
reach[j] |= reach[l];
}
}
}
for (ull x : same) {
/*
* x と lower の全モンスターを倒した後の攻撃力。
* 逆向きには、この値から開始する。
*/
ull finalPower = B ^ totalXor ^ x;
// 0 からなら、どのモンスターも逆向きに追加できる
if (finalPower == 0) {
cout << base + 1 << '\n';
return 0;
}
int start = msb(finalPower);
/*
* 到達可能な最高位 l のどこかで
* x の第 l ビットが0なら、xを逆向きに追加できる。
*/
if ((reach[start] & ~x) != 0) {
cout << base + 1 << '\n';
return 0;
}
}
cout << base << '\n';
return 0;
}