QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#223057 | #6838. Assumption is All You Need | pigpigger | WA | 0ms | 3944kb | C++14 | 1.1kb | 2023-10-21 21:03:04 | 2023-10-21 21:03:04 |
Judging History
answer
#include<bits/stdc++.h>
#define de fprintf(stderr,"on-%d\n",__LINE__)
//#define int long long
#define fr(i,a,b) for(int i(a),end##i(b);i<=end##i;i++)
#define fd(i,a,b) for(int i(a),end##i(b);i>=end##i;i--)
#define fi first
#define se second
#define pii pair<int,int>
#define mk make_pair
using namespace std;
const int maxn=2500;
int n;
int a[maxn],b[maxn],p[maxn],q[maxn];
pii ans[maxn*maxn];
int top;
void solve(){
scanf("%d",&n);
fr(i,1,n){
scanf("%d",&a[i]);
p[a[i]]=i;
}
fr(i,1,n){
scanf("%d",&b[i]);
q[b[i]]=i;
}
top=0;
fr(i,1,n){
if(p[i]<q[i]||a[q[i]]<i){
printf("-1\n");
return ;
}
int pre=p[i];
fd(j,p[i]-1,q[i])if(a[j]>i){
p[a[j]]=pre;
a[pre]=a[j];
ans[++top]=mk(j,pre);
pre=j;
}
a[q[i]]=i;
p[i]=q[i];
//fr(j,1,n)printf("%d ",a[j]);printf("\n");
}
printf("%d\n",top);
fr(i,1,top)printf("%d %d\n",ans[i].fi,ans[i].se);
}
signed main(){
#ifdef pig
freopen("pig.in","r",stdin);
freopen("pig.out","w",stdout);
#endif
int t;cin>>t;
while(t--){
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3944kb
input:
3 2 1 2 2 1 4 4 1 2 3 1 3 2 4 8 8 7 6 5 4 3 2 1 1 8 7 6 5 4 3 2
output:
-1 2 1 2 2 4 7 7 8 6 7 5 6 4 5 3 4 2 3 1 2
result:
ok T=3
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 3932kb
input:
315 10 8 4 6 1 2 9 7 5 10 3 6 7 8 10 5 1 3 2 9 4 10 10 8 2 9 6 5 7 4 3 1 7 1 3 5 9 8 4 10 6 2 6 4 6 5 3 1 2 1 5 4 6 2 3 12 5 9 12 8 10 6 11 4 2 3 1 7 9 2 3 1 5 12 4 7 6 10 8 11 10 4 7 3 2 8 9 6 10 5 1 1 4 8 10 3 7 9 6 2 5 7 1 2 4 5 6 7 3 4 3 5 6 7 2 1 3 1 3 2 2 1 3 7 1 5 3 7 6 4 2 6 5 2 1 3 4 7 1 1 ...
output:
-1 -1 -1 -1 -1 -1 -1 -1 0 -1 -1 -1 -1 -1 -1 -1 0 0 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 0 0 -1 -1 -1 -1 -1 -1 0 0 -1 -1 0 -1 -1 -1 1 1 2 -1 2 1 2 2 3 -1 -1 0 -1 -1 2 2 3 3 4 -1 -1 -1 0 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 0 -1 -1 -1 -1 -1 -1 -1 -1 1 1 2 -1 -1 -1 ...
result:
wrong answer Case #2: Jury has the answer but participant has not