QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#166461 | #4810. Add One | training4usaco | WA | 1ms | 3652kb | C++17 | 1.1kb | 2023-09-06 13:08:34 | 2023-09-06 13:08:34 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int, int>
#define ff first
#define ss second
const int MAXN = 1e6 + 5;
const int LOG = 62;
int n;
int xorsum = 0;
int a[MAXN];
int basis[LOG];
int sz;
void magic(int mask) {
// cout << "mask: " << mask << endl;
for(int i = LOG - 1; i >= 0; --i) {
if(!(mask & (1ll << i))) continue;
// cout << i << "," << (1ll << i) << "; ";
if(!basis[i]) {
basis[i] = mask; ++sz;
return;
}
mask ^= basis[i];
}
}
bool check(int k) {
int mask = (1ll << k) - 1;
for(int i = k; i >= 0; --i) {
if(!(mask & (1ll << i))) continue;
if(!basis[i]) return false;
mask ^= basis[i];
}
return true;
}
signed main() {
cin.tie(0)->sync_with_stdio(false);
cin >> n;
xorsum = 0;
for(int i = 1; i <= n; ++i) {
cin >> a[i]; magic(a[i]);
xorsum ^= a[i];
}
int ans = 0;
int mask = 0;
for(int k = 0; k <= 60; ++k) {
mask ^= basis[k];
ans = max(ans, xorsum ^ mask ^ (mask + 1));
if(check(k + 1)) ans = max(ans, xorsum ^ ((1ll << (k + 2)) - 1));
}
cout << ans << endl;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3604kb
input:
4 1 2 1 2
output:
7
result:
ok 1 number(s): "7"
Test #2:
score: 0
Accepted
time: 1ms
memory: 3524kb
input:
5 1 2 3 4 5
output:
14
result:
ok 1 number(s): "14"
Test #3:
score: 0
Accepted
time: 1ms
memory: 3528kb
input:
6 1 2 4 7 15 31
output:
47
result:
ok 1 number(s): "47"
Test #4:
score: 0
Accepted
time: 1ms
memory: 3612kb
input:
5 41 40 50 11 36
output:
99
result:
ok 1 number(s): "99"
Test #5:
score: 0
Accepted
time: 1ms
memory: 3612kb
input:
6 10 40 60 2 44 47
output:
96
result:
ok 1 number(s): "96"
Test #6:
score: 0
Accepted
time: 1ms
memory: 3652kb
input:
6 46 25 39 47 23 60
output:
107
result:
ok 1 number(s): "107"
Test #7:
score: -100
Wrong Answer
time: 1ms
memory: 3536kb
input:
6 56 90 61 63 56 23
output:
78
result:
wrong answer 1st numbers differ - expected: '112', found: '78'