QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#166458#4810. Add Onetraining4usacoWA 2ms3648kbC++171.1kb2023-09-06 13:05:412023-09-06 13:05:41

Judging History

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

  • [2023-09-06 13:05:41]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:3648kb
  • [2023-09-06 13:05:41]
  • 提交

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 + 1)) - 1));
	}
	cout << ans << endl;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 3644kb

input:

4
1 2 1 2

output:

7

result:

ok 1 number(s): "7"

Test #2:

score: 0
Accepted
time: 1ms
memory: 3628kb

input:

5
1 2 3 4 5

output:

14

result:

ok 1 number(s): "14"

Test #3:

score: -100
Wrong Answer
time: 2ms
memory: 3648kb

input:

6
1 2 4 7 15 31

output:

31

result:

wrong answer 1st numbers differ - expected: '47', found: '31'