QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#166447#4810. Add Onetraining4usacoWA 1ms3512kbC++171.1kb2023-09-06 12:43:072023-09-06 12:43:08

Judging History

你现在查看的是最新测评结果

  • [2023-09-06 12:43:08]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3512kb
  • [2023-09-06 12:43:07]
  • 提交

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;
}

Details

Tip: Click on the bar to expand more detailed information

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'