QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#610627 | #6838. Assumption is All You Need | wangcq | WA | 1ms | 3816kb | C++23 | 1.5kb | 2024-10-04 16:43:03 | 2024-10-04 16:43:04 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
const int N = 100010;
typedef long long ll;
typedef pair<int, int> pii;
std::mt19937 rng {std::chrono::steady_clock::now().time_since_epoch().count()};
template <typename T>
void debug(T x) {
cerr << x << '\n';
}
template <typename T, typename... Args>
void debug(T x, Args... args) {
cerr << x << ' ';
debug(args...);
}
void solve() {
int n;
cin >> n;
vector<int> a(n + 1), b(n + 1);
map<int, int> idx_a, idx_b;
for (int i = 1; i <= n; i ++ ) {
cin >> a[i];
idx_a[a[i]] = i;
}
for (int i = 1; i <= n; i ++ ) {
cin >> b[i];
idx_b[b[i]] = i;
}
int now = n;
bool ok = 0;
vector<pii> ans;
while (now) {
if (idx_a[now] == idx_b[now]) {
now --;
continue;
} else if (idx_a[now] > idx_b[now]) {
ok = 1;
break;
} else {
ans.push_back({idx_a[now], idx_b[now]});
swap(a[idx_a[now]], a[idx_b[now]]);
swap(idx_a[a[idx_a[now]]], idx_a[a[idx_b[now]]]);
now --;
}
}
if (ok) {
cout << -1 << '\n';
} else {
cout << ans.size() << '\n';
for (auto [x, y] : ans) {
cout << x << ' ' << y << '\n';
}
}
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int T = 1;
cin >> 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: 3816kb
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 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: 3628kb
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 -1 -1 -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 4 3 6 2 5 3 4 1 3 2 1 3 1 2 -1 -1 0 -1 -1 2 2 4 2 3 -1 -1 -1 0 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 0 -1...
result:
wrong answer Case #2: Jury has the answer but participant has not