QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#517982#6511. Balancing SequencesDaiRuiChen007WA 469ms4120kbC++17924b2024-08-13 15:01:502024-08-13 15:01:51

Judging History

你现在查看的是最新测评结果

  • [2024-08-13 15:01:51]
  • 评测
  • 测评结果:WA
  • 用时:469ms
  • 内存:4120kb
  • [2024-08-13 15:01:50]
  • 提交

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;
}

詳細信息

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)