QOJ.ac
QOJ
ID | Submission ID | Problem | Hacker | Owner | Result | Submit time | Judge time |
---|---|---|---|---|---|---|---|
#920 | #593490 | #21792. 【NOIP Round #6】抉择 | houpingze | houpingze | Failed. | 2024-09-27 14:24:29 | 2024-09-27 14:24:32 |
Details
Extra Test:
Accepted
time: 1ms
memory: 5848kb
input:
5 4 2 3 1 5
output:
4
result:
ok 1 number(s): "4"
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#593490 | #21792. 【NOIP Round #6】抉择 | houpingze | 100 ✓ | 266ms | 20500kb | C++14 | 589b | 2024-09-27 14:20:41 | 2024-09-27 14:20:42 |
answer
#include<bits/stdc++.h>
#define int long long
#define rep(i,x,y) for(int i=x;i<=y;i++)
using namespace std;
int n;
int a[1145141];
int f[1000050];
int lst[1145];
signed main(){
cin>>n;
rep(i,1,n) {
scanf("%lld",&a[i]);
}
f[1]=0;
f[2]=(a[1]&a[2]);
rep(i,1,2){
rep(j,0,50){
if(a[i]&(1ll<<j)){
lst[j]=i;
}
}
}
for(int i=3;i<=n;i++){
rep(j,0,50){
f[i]=max(f[i],f[lst[j]]+(a[lst[j]]&a[i]));
}
rep(j,0,50){
if(a[i]&(1ll<<j)){
lst[j]=i;
}
}
}
int ans=0;
rep(i,1,n) ans=max(ans,f[i]);
cout<<ans;
return 0;
}