QOJ.ac
QOJ
The 2nd Universal Cup Finals is coming! Check out our event page, schedule, and competition rules!
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#141381 | #6521. Swapping Operation | cy1999 | WA | 107ms | 5712kb | C++ | 1002b | 2023-08-17 11:18:33 | 2023-08-17 11:18:35 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
int n,p[100005],ans,t,res,qz[100005],hz[100005],mx;
void solve(){
int res=0;
qz[0]=(1<<31)-1;
hz[n+1]=(1<<31)-1;
for(int i=1;i<=n;i++)qz[i]=qz[i-1]&p[i];
for(int i=n;i>=1;i--)hz[i]=hz[i+1]&p[i];
for(int i=1;i<n;i++)res=max(res,qz[i]+hz[i+1]);
ans=max(ans,res);
}
signed main(){
cin>>t;
while(t--){
cin>>n;
for(int i=1;i<=n;i++){
scanf("%lld",&p[i]);
if(p[i]>p[mx])mx=i;
}
ans=0;
solve();
for(int i=1;i<=20;i++){
if(i>n)continue;
for(int j=n;j>=n-20;j--){
if(i>n||j<1)continue;
swap(p[i],p[j]);
solve();
swap(p[i],p[j]);
}
swap(p[i],p[mx]);
solve();
swap(p[i],p[mx]);
}
for(int i=n;i>=n-20;i--){
for(int j=1;j<=20;j++){
if(j<=n&&i>=1){
swap(p[i],p[j]);
solve();
swap(p[i],p[j]);
}
}
if(i>=1){
swap(p[i],p[mx]);
solve();
swap(p[i],p[mx]);
}
}
printf("%lld\n",ans);
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3888kb
input:
3 6 6 5 4 3 5 6 6 1 2 1 1 2 2 5 1 1 2 2 2
output:
7 3 3
result:
ok 3 number(s): "7 3 3"
Test #2:
score: -100
Wrong Answer
time: 107ms
memory: 5712kb
input:
1000 100 803046221 177233942 164782937 53823867 383853667 250036100 888743479 576687945 737272231 801579441 647643785 393059353 401516062 663466861 308544510 825328494 162739603 501761995 570908380 655227403 444493122 844535039 208303132 493226172 421479971 634680694 396627047 787471115 335787136 16...
output:
999397418 953601453 996676598 986700621 959469962 997532753 979836345 998064178 978672351 989100873 997784581 990111329 976588292 999515942 981686922 998122389 999751601 995753373 995915998 932273461 994686107 986433302 981799808 992366273 991166895 978772754 993464658 980800625 985148851 993204707 ...
result:
wrong answer 7th numbers differ - expected: '991939977', found: '979836345'