QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#166447 | #4810. Add One | training4usaco | WA | 1ms | 3512kb | C++17 | 1.1kb | 2023-09-06 12:43:07 | 2023-09-06 12:43:08 |
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 i) {
int mask = (1 << i) - 1;
for(int j = i; j >= 0; --j) {
if(!(mask & (1ll << j))) continue;
if(!basis[j]) return false;
mask ^= basis[j];
}
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)) ans = max(ans, xorsum ^ ((1 << (k + 1)) - 1));
}
cout << ans << endl;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3380kb
input:
4 1 2 1 2
output:
7
result:
ok 1 number(s): "7"
Test #2:
score: 0
Accepted
time: 1ms
memory: 3508kb
input:
5 1 2 3 4 5
output:
14
result:
ok 1 number(s): "14"
Test #3:
score: 0
Accepted
time: 1ms
memory: 3436kb
input:
6 1 2 4 7 15 31
output:
47
result:
ok 1 number(s): "47"
Test #4:
score: 0
Accepted
time: 1ms
memory: 3512kb
input:
5 41 40 50 11 36
output:
99
result:
ok 1 number(s): "99"
Test #5:
score: 0
Accepted
time: 1ms
memory: 3428kb
input:
6 10 40 60 2 44 47
output:
96
result:
ok 1 number(s): "96"
Test #6:
score: 0
Accepted
time: 0ms
memory: 3376kb
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: 3448kb
input:
6 56 90 61 63 56 23
output:
78
result:
wrong answer 1st numbers differ - expected: '112', found: '78'