QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#511392 | #6838. Assumption is All You Need | ucup-team3474 | RE | 0ms | 67336kb | C++23 | 1.4kb | 2024-08-09 20:23:44 | 2024-08-09 20:23:44 |
Judging History
answer
#include <bits/stdc++.h>
#include <ctime>
#include <cstdio>
using namespace std;
#define pi = 3.14159265358979323846
#define int long long
typedef pair<int,int> pii ;
const int N = 2030;
int a[N],b[N];
vector<pii>vis(N*N);
void solve()
{
int n;
cin >> n;
vector<pii> ans;
for(int i=1;i<=n;i++){
cin >> a[i];
vis[a[i]].first = i;
}
for(int i=1;i<=n;i++){
cin >> b[i];
vis[b[i]].second = i;
}
int flag = 1;
for(int i=n;i>=1;i--){
while(vis[i].first > vis[i].second){
int id = vis[i].first - 1;
while(id >= 1 && (vis[a[id]].second < vis[i].first || a[id] < i)){
id-- ;
}
if(id < 1) break;
ans.push_back({id,vis[i].first});
a[vis[i].first] = a[id];
vis[a[id]].first = vis[i].first;
vis[i].first = id;
a[id] = i;
}
if(vis[i].first > vis[i].second){
flag = 0;
break;
}
}
if(flag == 0){
cout << -1 << "\n";
return ;
}
cout << ans.size() << "\n";
for(int i=0;i<=ans.size()-1;i++){
cout << ans[i].first << " " << ans[i].second << "\n";
}
}
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t = 1;
cin >> t;
while (t--)
{
solve();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 67336kb
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 4 1 2 7 7 8 6 7 5 6 4 5 3 4 2 3 1 2
result:
ok T=3
Test #2:
score: -100
Runtime Error
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 ...