QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#373178 | #8307. Club Assignment | kevinyang# | WA | 121ms | 3892kb | C++23 | 2.2kb | 2024-04-01 06:01:17 | 2024-04-01 06:01:19 |
Judging History
answer
#include <iostream>
#include <vector>
#include <cassert>
using namespace std;
using ll = long long;
const ll inf = 1e18;
using vl = vector<ll>;
vector<vector<vector<int>>> parts[5];
ll xorVl(vl &vals) {
if (vals.size() == 0) return inf;
ll a = 0;
for (ll i : vals) a^= i;
return a;
}
vl arr;
struct Ans {
ll a = inf, b = inf;
vl l, r;
bool operator<(const Ans &rhs) const {
return min(a,b) < min(rhs.a, rhs.b);
}
};
Ans solve(vl vals, int bit=31) {
if (vals.size() == 0) {
return {inf, inf, {}, {} };
}
if (vals.size() == 1) {
return {vals[0], inf, vals, {} };
}
if (bit == -1) {
for (int i = 1; i < vals.size(); i++) assert(arr[vals[i]] == arr[vals[0]]);
vals.pop_back();
return { 0, inf, vals, {vals[0]} };
}
vl l, r;
for (ll i : vals) {
if (arr[i]&(1<<bit)) r.push_back(i);
else l.push_back(i);
}
if (r.size() == 2) {
if (l.size() == 0) {
Ans a = { arr[r[0]], arr[r[1]], { r[0] }, { r[1] } };
return a;
}
if (l.size() == 1) {
Ans a = { arr[l[0]] ^ arr[r[0]], arr[r[1]], { l[0], r[0] }, { r[1] } };
Ans b = { arr[l[0]] ^ arr[r[1]], arr[r[0]], { l[0], r[1] }, { r[0] } };
return max(a,b);
}
else if (l.size() == 2) {
Ans a = { arr[l[0]] ^ arr[r[0]], arr[l[1]] ^ arr[r[1]], { l[0], r[0] }, { l[1], r[1] } };
Ans b = { arr[l[0]] ^ arr[r[1]], arr[l[1]] ^ arr[r[0]], { l[0], r[1] }, { l[1], r[0] } };
return max(a,b);
}
}
Ans x = solve(l, bit-1), y = solve(r, bit-1);
Ans out = { min(x.a, y.a), min(x.b, y.b), {}, {} };
while (x.l.size()) {
out.l.push_back(x.l.back());
x.l.pop_back();
}
while (y.l.size()) {
out.l.push_back(y.l.back());
y.l.pop_back();
}
while (x.r.size()) {
out.r.push_back(x.r.back());
x.r.pop_back();
}
while (y.r.size()) {
out.r.push_back(y.r.back());
y.r.pop_back();
}
return out;
}
void solve() {
int n; cin >> n;
arr.resize(n);
for (ll &i : arr) cin >> i;
vl idxs(n);
for (int i = 0; i < n; i++) idxs[i] = i;
Ans out = solve(idxs);
cout << min(out.a, out.b) << endl;
vector<int> col(n, 1);
for (int i : out.l) col[i] = 2;
for (int i : col) cout << 2 - (i == col[0]);
cout << endl;
}
int main() {
int t; cin >> t;
while (t--) solve();
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3640kb
input:
2 3 1 2 3 3 5 5 5
output:
3 112 0 112
result:
ok accepted
Test #2:
score: -100
Wrong Answer
time: 121ms
memory: 3892kb
input:
2000 100 7 90 64 59 9 12 72 41 72 45 35 90 65 43 81 37 49 62 42 61 12 3 30 97 3 21 43 44 18 71 3 8 70 25 55 41 43 26 80 36 11 6 36 5 57 7 35 23 72 27 73 45 2 64 86 90 47 93 54 26 7 48 63 40 1 61 35 45 11 80 90 68 20 6 22 92 57 47 37 8 84 43 51 95 20 44 89 25 65 18 79 77 5 2 85 62 63 27 62 72 100 34 ...
output:
0 1111111111111111111121111111112121121111112111111111121111222111122222211211222212112212221122112222 0 1111111111112121112111111111111111111111121211111211111211121211122112211111221112221222212122221122 0 11111111112111111211111111111111111111111212111121121211112112211121211222121211112112121212...
result:
wrong answer ans=1 instead of 0