OI Debug智能代码调试
v2
DEBUG SESSION #568
GPT-5.6 Luna (xhigh)
推理强度 xhigh · 2026-08-08 22:25 · 已工作 2 min 46 s
题面与错误信息
提交的代码 Time Limit Exceeded
#include <bits/stdc++.h>
using namespace std;
const int MAX_BIT = 30;
int T;
int n;
struct node {
struct trie {
int nxt[2];
trie () {
nxt[0] = nxt[1] = 0;
}
};
vector<trie> t;
node () {
t.resize(MAX_BIT + 5);
t.push_back(trie());
}
void add(int s) {
int p = 0;
for (int i = MAX_BIT; i >= 0; i--) {
int x = (s >> i) & 1;
if (!t[p].nxt[x]) {
t[p].nxt[x] = t.size();
t.push_back(trie());
}
p = t[p].nxt[x];
}
}
int query(int s) {
int p = 0;
for (int i = MAX_BIT; i >= 0; i--) {
int x = (s >> i) & 1;
if (!t[p].nxt[x]) return 0;
p = t[p].nxt[x];
}
return (1 << MAX_BIT);
}
};
void solve() {
cin >> n;
node t;
for (int i = 1; i <= n; i++) {
int a;
cin >> a;
t.add(a);
}
int ans = n;
for (int i = 0; i <= n && i < ans; i++) {
int mex = t.query(i);
ans = min(ans, i + mex);
}
cout << ans << '\n';
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> T;
while (T--) solve();
return 0;
}