QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#265912 | #6838. Assumption is All You Need | kokomiisbest | WA | 1ms | 3384kb | C++14 | 1.1kb | 2023-11-25 22:25:13 | 2023-11-25 22:25:14 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
struct node{
int l,r;
}ans[2500];
int a[2500],b[2500],p[2500],tar[2500];
int main()
{
int n,i,j,k,t;
cin>>t;
while(t--)
{
cin>>n;int flag=1;
for(i=1;i<=n;i++)
{
cin>>a[i];p[a[i]]=i;
}
for(i=1;i<=n;i++)
{
cin>>b[i];tar[b[i]]=i;
}
int cnt=0;
for(i=n;i>=1;i--)
{
if(p[i]>tar[i])
{
flag=0;break;
}
for(j=n-1;j>=1;j--)
{
if(tar[j]<p[j]&&p[j]<tar[i]&&p[i]<p[j])
{
ans[++cnt].l=p[i];ans[cnt].r=p[j];
swap(a[p[i]],a[p[j]]);
swap(p[i],p[j]);
// cout<<a[1]<<a[2]<<a[3]<<a[4]<<a[5]<<a[6]<<endl;
// cout<<p[1]<<p[2]<<p[3]<<p[4]<<p[5]<<p[6]<<endl;
}
}
if(tar[i]!=p[i])
{
// cout<<"ok\n";
ans[++cnt].l=p[i];ans[cnt].r=tar[i];
swap(a[p[i]],a[tar[i]]);
swap(p[i],p[a[p[i]]]);
// cout<<a[1]<<a[2]<<a[3]<<a[4]<<a[5]<<a[6]<<endl;
// cout<<p[1]<<p[2]<<p[3]<<p[4]<<p[5]<<p[6]<<endl;
}
}
if(!flag) cout<<"-1\n";
else
{
cout<<cnt<<'\n';
for(i=1;i<=cnt;i++) cout<<ans[i].l<<" "<<ans[i].r<<'\n';
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3384kb
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 1 2 1 3 1 4 1 5 1 6 1 7 1 8
result:
ok T=3
Test #2:
score: -100
Wrong Answer
time: 1ms
memory: 3356kb
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 8 1 7 7 8 4 5 2 6 4 9 2 4 2 3 2 10 5 2 3 3 4 1 3 1 5 5 6 -1 -1 -1 -1 -1 0 -1 -1 -1 3 4 5 1 2 1 6 -1 -1 -1 0 0 -1 -1 -1 -1 -1 -1 -1 -1 -1 3 2 4 1 2 1 5 -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 6 3 5 5 6 2 3 3 4 4 5 1 3 2 1 2 2 3 -1 -1 0 -1 -1 2 2 3 3 4 -1 -1 -1 0 -1 -1 -1...
result:
wrong answer Case #185: Jury has the answer but participant has not