(https://atcoder.jp/contests/abc141/tasks/abc141_f
Problem Statement
We have NN.
Constraints
- All values in input are integers.
- 2≤N≤1052≤N≤105
Input
Input is given from Standard Input in the following format:
NN
Output
Print the maximum possible beauty of the painting.
Sample Input 1 Copy
Copy
3 3 6 5
Sample Output 1 Copy
Copy
12
If we paint 33.
Sample Input 2 Copy
Copy
4 23 36 66 65
Sample Output 2 Copy
Copy
188
Sample Input 3 Copy
Copy
20 1008288677408720767 539403903321871999 1044301017184589821 215886900497862655 504277496111605629 972104334925272829 792625803473366909 972333547668684797 467386965442856573 755861732751878143 1151846447448561405 467257771752201853 683930041385277311 432010719984459389 319104378117934975 611451291444233983 647509226592964607 251832107792119421 827811265410084479 864032478037725181
Sample Output 3 Copy
Copy
2012721721873704572
AiAi-bit integer type.
AC Code
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n;
ll A[100005];
ll B[65];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n;
ll sum = 0;
for (int i = 1; i <= n; ++i) {
cin >> A[i];
sum ^= A[i];
}
for (int i = 1; i <= n; ++i) {
A[i] = A[i] & ~sum;
for (int j = 60; j--;) {
if ((A[i] >> j) & 1) {
if (B[j] == 0) {
B[j] = A[i];
break;
} else {
A[i] ^= B[j];
}
}
}
}
ll x = 0;
for (int i = 60; i--;)
x = max(x, x ^ B[i]);
cout << (x + (x ^ sum));
return 0;
}