QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#353394 | #7933. Build Permutation | ucup-team1004# | WA | 44ms | 6168kb | C++14 | 1.1kb | 2024-03-14 08:12:09 | 2024-03-14 08:12:10 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define all(a) (a).begin(),(a).end()
#ifdef DEBUG
template<class T>
ostream& operator << (ostream &out,vector<T> a){
out<<'[';
for(T x:a)out<<x<<',';
return out<<']';
}
template<class T>
vector<T> ary(T *a,int l,int r){
return vector<T>{a+l,a+1+r};
}
template<class T>
void debug(T x){
cerr<<x<<endl;
}
template<class T,class...S>
void debug(T x,S...y){
cerr<<x<<' ',debug(y...);
}
#else
#define debug(...) void()
#endif
const int N=2e5+10;
int n,a[N],cur[N],p[N];
int main(){
scanf("%d",&n);
for(int i=1;i<=n;i++)scanf("%d",&a[i]);
iota(cur,cur+1+n,0);
sort(cur+1,cur+1+n,[](int x,int y){
return a[x]<a[y];
});
int sum=a[cur[1]]+a[cur[n]];
for(int l=1,r=n;l<=r;){
int i=0,j=0;
for(;l+i<=r&&a[cur[l+i]]==a[cur[l]];i++);
for(;r-j>=l&&a[cur[r-j]]==a[cur[r]];j++);
if(i!=j)puts("-1"),exit(0);
if(i==r-l+1){
for(int i=l;i<=r;i++){
p[cur[i]]=cur[i];
}
}else{
for(int k=0;k<i;k++)p[cur[l+k]]=cur[r-k],p[cur[r-k]]=cur[l+k];
}
l+=i,r-=j;
}
for(int i=1;i<=n;i++)printf("%d%c",p[i],"\n "[i<n]);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3824kb
input:
5 4 2 5 1 3
output:
2 1 4 3 5
result:
ok
Test #2:
score: 0
Accepted
time: 0ms
memory: 3776kb
input:
3 2 2 3
output:
-1
result:
ok
Test #3:
score: 0
Accepted
time: 31ms
memory: 6044kb
input:
199528 581552649 419782901 924554494 589802859 878336763 659984178 419820729 521791999 956262027 523946290 442086405 808419260 875183942 860794919 584899704 494193909 687014591 794119827 641706288 734029639 795387770 803653459 889799156 455122734 655375888 757642629 427654115 987811208 593072829 584...
output:
-1
result:
ok
Test #4:
score: 0
Accepted
time: 38ms
memory: 6084kb
input:
199680 774760412 315033238 665140012 402128528 221827348 923752357 281703052 551555739 483983889 622621809 949928382 909484599 413397988 424613137 353323926 392255354 551928848 464853065 860603765 618364501 423106762 752293338 551415838 898671881 969815739 150102831 644806419 333507443 379455235 981...
output:
73439 148005 8648 89423 141979 147470 141410 69725 40153 63979 78432 103327 181609 135195 105239 127546 32464 34284 174446 34920 30629 168594 168530 161118 93855 108316 180454 174923 1995 85530 196615 98831 140833 5779 144616 158480 4431 142576 165252 72206 116180 122123 113985 60323 86875 40860 134...
result:
ok
Test #5:
score: -100
Wrong Answer
time: 44ms
memory: 6168kb
input:
199443 280209150 111548592 486449150 830619773 101477510 250948810 530722572 122879826 934988883 597990248 855838792 673988482 368821924 128160089 591934983 960002116 507933024 995671195 672047771 312730948 102630166 364851921 555488581 895717854 273833610 945841457 136208436 989527045 110773712 399...
output:
125217 2188 74459 98624 178475 161814 160269 9562 127693 118363 131355 73371 90792 62133 199295 119843 43141 184998 93183 7514 141383 80908 109265 176039 144873 137357 138919 96757 40717 66025 34838 102960 8235 197315 110225 83063 25538 71221 115646 114920 179628 136168 194876 10871 146482 59232 242...
result:
wrong answer Integer 125217 violates the range [-1, -1]