QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#137562 | #2351. Lost in Transfer | BoulevardDust# | 0 | 4ms | 3732kb | C++20 | 1.6kb | 2023-08-10 13:58:27 | 2023-08-10 13:59:35 |
Judging History
answer
#include<bits/stdc++.h>
#define N 300005
#define re
#define ll long long
using namespace std;
int n,m,K,q,T;
inline void Rd(int &res){
re char c;res=0;
while(c=getchar(),c<48);
do res=(res<<3)+(res<<1)+(c^48);
while(c=getchar(),c>47);
}
char c[25];
int a[N],b[N];
ll up;
ll query(int n){
ll ans=0;
for(int i=1;i<n;i++){
int t=0;
for(int j=n;j>i;j--)if(a[j]<a[i])t++;
ans=(ans+t)*(n-i);
if(ans>up)return -1;
}
return ans;
}
int main(){
scanf("%s",c+1);
if(c[1]=='t'){
Rd(T);
while(T--){
Rd(n);
ll sum=0;
for(re int i=1;i<=n;i++)Rd(a[i]),sum+=a[i];
sort(a+1,a+n+1);
while(sum--){
next_permutation(a+1,a+n+1);
}
for(re int i=1;i<=n;i++){
printf("%d",a[i]);
putchar(i==n?'\n':' ');
}
}
}
else{
Rd(T);
while(T--){
Rd(n);
ll sum=0;
for(re int i=1;i<=n;i++)Rd(a[i]),sum+=a[i],b[i]=a[i];
up=sum+500;
ll res=query(n);
if(res==sum){
for(re int i=1;i<=n;i++){
printf("%d",a[i]);
putchar(i==n?'\n':' ');
}
continue;
}
bool flag=0;
for(re int v=1;!flag&&v<=500;v++){
bool f=1;
for(re int i=1;i<=n;i++)
if(b[i]==v)f=0;
if(!f)continue;
for(re int i=1;!flag&&i<=n+1;i++){
a[i]=v;
int t=1;
for(re int j=1;j<=n;j++){
if(t==i)t++;
a[t]=b[j];t++;
}
ll res=query(n+1);
if(res!=-1&&res==sum+v){
flag=1;
for(re int i=1;i<=n+1;i++){
printf("%d",a[i]);
putchar(i==n+1?'\n':' ');
}
}
}
}
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 4ms
memory: 3732kb
input:
transmit 2 20 97 388 459 467 32 99 98 296 403 325 330 271 87 333 378 267 405 58 426 374 20 125 481 451 150 495 136 444 192 118 26 68 281 120 61 494 339 86 292 100 32
output:
32 58 87 97 98 99 267 271 296 325 330 333 378 374 459 426 388 403 467 405 26 32 61 68 86 100 118 120 125 136 150 192 281 495 339 451 292 481 494 444
input:
recover 2 19 32 58 87 97 98 99 267 271 296 325 330 333 378 374 459 426 388 403 467 19 26 32 61 68 100 118 120 125 136 150 192 281 495 339 451 292 481 494 444
output:
32 58 87 97 98 99 267 271 296 325 330 333 378 374 459 426 388 403 404 467 26 32 61 68 86 100 118 120 125 136 150 192 281 495 339 451 292 481 494 444
result:
wrong answer incorrect answer. (test case 1)