QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#149923 | #4810. Add One | LD_ZJR_FG | WA | 1ms | 3860kb | C++14 | 1.0kb | 2023-08-25 14:34:55 | 2023-08-25 14:34:57 |
Judging History
answer
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N=1e6+5,mod=1e9+7;
void chkmax(int &x,int y){x=max(x,y);}
void chkmin(int &x,int y){x=min(x,y);}
void Add(int &x,int y){x+=y,x%=mod;}
int ab(int x){if(x<0)x=-x;return x;}
int bit(int x,int i){return (x>>i)&1;}
int read(){
int x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9')x=x*10+(ch-'0'),ch=getchar();
return x*f;
}
int n,a[N],f[65];
int insert(int x,int ok){
for(int i=60;i>=0;i--){
if(!bit(x,i))continue;
if(f[i])x^=f[i];
else{if(!ok)f[i]=x;return 1;}
}
return 0;
}
void init(){
for(int i=1,ok=0;i<=n;i++)ok=insert(a[i],0);
}
signed main(void){
n=read();
int sum=0,ans=0;
for(int i=1;i<=n;i++)a[i]=read(),sum^=a[i];
init();
for(int i=1;i<=60;i++){
int x=(1<<i)-1,ok=insert(x-(1<<(i-1)),1);
if(!ok)chkmax(ans,sum^x);
}
printf("%lld\n",ans);
return 0;
}
//start coding at
//finish coing at
//accept at
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3768kb
input:
4 1 2 1 2
output:
7
result:
ok 1 number(s): "7"
Test #2:
score: 0
Accepted
time: 1ms
memory: 3860kb
input:
5 1 2 3 4 5
output:
14
result:
ok 1 number(s): "14"
Test #3:
score: 0
Accepted
time: 1ms
memory: 3780kb
input:
6 1 2 4 7 15 31
output:
47
result:
ok 1 number(s): "47"
Test #4:
score: 0
Accepted
time: 1ms
memory: 3716kb
input:
5 41 40 50 11 36
output:
99
result:
ok 1 number(s): "99"
Test #5:
score: 0
Accepted
time: 1ms
memory: 3776kb
input:
6 10 40 60 2 44 47
output:
96
result:
ok 1 number(s): "96"
Test #6:
score: 0
Accepted
time: 1ms
memory: 3788kb
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: 3736kb
input:
6 56 90 61 63 56 23
output:
78
result:
wrong answer 1st numbers differ - expected: '112', found: '78'