QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#511400 | #6838. Assumption is All You Need | ucup-team3474 | WA | 0ms | 3576kb | C++23 | 1.7kb | 2024-08-09 20:33:41 | 2024-08-09 20:33:41 |
Judging History
answer
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
void solve() {
int T;
cin >> T;
while (T--) {
int n;
cin >> n;
vector<int> A(n), B(n);
for (int i = 0; i < n; ++i) cin >> A[i];
for (int i = 0; i < n; ++i) cin >> B[i];
// 检查 A 和 B 是否可以通过排序一致
vector<int> sortedA = A, sortedB = B;
sort(sortedA.begin(), sortedA.end());
sort(sortedB.begin(), sortedB.end());
if (sortedA != sortedB) {
cout << -1 << endl;
continue;
}
vector<pair<int, int>> swaps;
// 通过交换将 A 转换为 B
for (int i = 0; i < n; ++i) {
if (A[i] != B[i]) {
for (int j = i + 1; j < n; ++j) {
if (A[j] == B[i]) {
// 将 A[j] 移动到 A[i] 位置
for (int k = j; k > i; --k) {
if (A[k] < A[k - 1]) {
cout << -1 << endl;
break;
}
swaps.push_back({k, k - 1});
swap(A[k], A[k - 1]);
}
break;
}
}
}
}
// 输出结果
cout << swaps.size() << endl;
for (const auto &p : swaps) {
cout << p.first + 1 << " " << p.second + 1 << endl;
}
}
}
int main() {
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3576kb
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 -1 3 4 3 3 2 4 3 -1 0
result:
wrong answer 1-th operation (2, 1) not valid: (x < y) == false