QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#652838#1842. Mathjiangzhihui#WA 1ms5904kbC++201.1kb2024-10-18 19:12:052024-10-18 19:12:06

Judging History

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

  • [2024-10-18 19:12:06]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5904kb
  • [2024-10-18 19:12:05]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int N=1919810;
typedef long long ll;
typedef pair<ll,ll> PII;
ll n,m,k;
ll a[N],b[N];
char s[N];
ll cnt[N];
int num[N];

void __(){
    scanf("%lld",&n);
    for(int i=1;i<=n;i++) scanf("%lld",&a[i]);
    sort(a+1,a+1+n,greater<ll>());
    int res=a[1];
    for(int i=1;i<=n;i++) res&=a[i];
    if(res!=a[n]){
        puts("-1");
        return;
    }
    vector<int> v1,v2;
    for(int i=1;i<n;i++){
        if(v1.size()==0){
            v1.push_back(a[i]);
        }else{
            int t=a[i]&v1.back();
            if(t==a[i]) v1.push_back(a[i]);
            else{
                v2.push_back(a[i]);
            }
        }
    }
    vector<int> ans;
    for(int i=0;i<v1.size();i++) ans.push_back(v1[i]);
    ans.push_back(a[n]);
    for(int i=v2.size()-1;i>=0;i--) ans.push_back(v2[i]);

    printf("%d\n",ans.size());
    for(int i=0;i<ans.size();i++) printf("%lld ",ans[i]);
    printf("\n"); 
}


int main(){
    int _=1;
    cin>>_;
    while(_--){
        __();
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 5904kb

input:

5
1 2 3 4 5

output:

1
2 
3
5 4 0 
3
5 4 0 
3
5 4 0 
3
5 4 0 

result:

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