QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#111677 | #6511. Balancing Sequences | Bird | WA | 70ms | 3860kb | C++14 | 1.2kb | 2023-06-07 21:10:35 | 2023-06-07 21:10:39 |
Judging History
answer
#include<bits/stdc++.h>
#define N 2000
using namespace std;
int T,n,a[N*2],b[N*2],pa[N*2],pb[N*2];
vector<pair<int,int>> ans;
inline void work(int u,int v)
{
ans.push_back({u,v});
swap(a[u],a[v]);
swap(pa[a[u]],pa[a[v]]);
}
inline bool check(int p) {return a[p]>a[p^1];}
inline void print(int u,int v)
{
printf("%d %d %d %d\n",(u&1)+1,(u>>1)+1,(v&1)+1,(v>>1)+1);
}
inline void solve()
{
ans.clear();
for(int i=0;i<n*2;++i)
{
int now=pa[i],to=pb[i];
if(now==to) continue;
if(!check(now)) return puts("-1"),void();
if(check(to)) work(now,to);
else
{
bool flag=1;
for(int j=i+1;j<to;++j)
if(check(pa[j]))
{
work(pa[j],to^1);
work(now,to);
flag=0;
break;
}
if(flag) return puts("-1"),void();
}
}
printf("%d\n",(int)ans.size());
for(pair<int,int> x:ans) print(x.first,x.second);
}
int main()
{
for(scanf("%d",&T);T--;)
{
scanf("%d",&n);
for(int i=0;i<2;++i)
for(int j=0;j<n;++j)
scanf("%d",&a[j<<1|i]);
for(int i=0;i<2;++i)
for(int j=0;j<n;++j)
scanf("%d",&b[j<<1|i]);
n*=2;
for(int i=0;i<n;++i)
pa[a[i]]=pb[b[i]]=i;
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3860kb
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: 70ms
memory: 3620kb
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 4 1 1 1 3 1 2 2 3 1 3 1 1 1 2 1 3 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 1 2 3 1 1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 1 2 2 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 564)