QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#517982 | #6511. Balancing Sequences | DaiRuiChen007 | WA | 469ms | 4120kb | C++17 | 924b | 2024-08-13 15:01:50 | 2024-08-13 15:01:51 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int MAXN=4005;
int n,a[MAXN],b[MAXN],p[MAXN],q[MAXN];
vector <array<int,4>> wys;
void opr(int x,int y) {
swap(a[x],a[y]),swap(p[a[x]],p[a[y]]);
wys.push_back({x/n+1,x%n+1,y/n+1,y%n+1});
}
int op(int x) { return x<n?x+n:x-n; }
void solve() {
scanf("%d",&n);
for(int i=0;i<2*n;++i) scanf("%d",&a[i]),p[--a[i]]=i;
for(int i=0;i<2*n;++i) scanf("%d",&b[i]),q[--b[i]]=i;
for(int i=0;i<2*n;++i) if(a[q[i]]!=i) {
if(a[op(p[i])]>i) return puts("-1"),void();
if(a[q[i]]>a[op(q[i])]) opr(p[i],q[i]);
else {
int z=0;
for(int j=i+1;j<a[q[i]];++j) if(j>a[op(p[j])]) { z=p[j]; break; }
if(!z) return puts("-1"),void();
else opr(z,op(q[i])),opr(q[i],p[i]);
}
}
printf("%d\n",(int)wys.size());
for(auto z:wys) printf("%d %d %d %d\n",z[0],z[1],z[2],z[3]);
}
signed main() {
int T; scanf("%d",&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: 3924kb
input:
2 2 1 2 3 4 4 3 2 1 3 1 2 4 3 5 6 1 2 4 5 3 6
output:
-1 1 2 1 2 2
result:
ok correct plan (nYES = 1, nNO = 1) (2 test cases)
Test #2:
score: -100
Wrong Answer
time: 469ms
memory: 4120kb
input:
100000 3 1 6 4 2 3 5 5 6 1 3 4 2 3 3 5 2 6 1 4 4 3 5 6 2 1 3 6 4 3 2 5 1 1 4 5 2 3 6 3 4 2 3 6 1 5 3 1 4 5 2 6 3 4 3 1 5 2 6 4 3 6 5 1 2 3 1 5 6 3 2 4 2 3 5 6 1 4 3 2 5 4 6 1 3 6 3 2 5 4 1 3 3 6 5 2 1 4 3 5 4 2 6 1 3 5 6 3 2 4 1 3 4 6 2 5 1 3 4 5 6 2 3 1 1 2 3 4 6 5 3 3 2 1 6 4 5 3 1 5 2 4 6 3 5 2 3...
output:
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 2 1 3 1 1 2 3 1 1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 3 1 3 1 1 2 3 1 1 2 2 1 1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -...
result:
wrong answer you didn't find a solution but jury did. (test case 50)