QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#511465 | #6838. Assumption is All You Need | ucup-team3474 | WA | 1ms | 3784kb | C++23 | 1.6kb | 2024-08-09 22:20:03 | 2024-08-09 22:20:03 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
int t;
cin >> t;
while (t--)
{
int n;
cin >> n;
vector<int> a(n + 1), b(n + 1),
posa(n + 1), posb(n + 1);
for (int i = 1; i <= n; i++)
{
cin >> a[i];
posa[a[i]] = i;
}
for (int i = 1; i <= n; i++)
{
cin >> b[i];
posb[b[i]] = i;
}
vector<pair<int, int>> ans;
auto swp = [&a, &posa, &ans](int i, int j)
{
ans.push_back({i, j});
swap(a[i], a[j]);
swap(posa[a[i]], posa[a[j]]);
};
while (a != b)
{
int i;
for (i = 1; i <= n; i++)
{
if ((i - posb[a[i]]) * (a[i] - a[posb[a[i]]]) > 0 || posb[a[i]] == i)
continue;
if ((i - posb[a[posb[a[i]]]]) * (a[posb[a[i]]] - a[posb[a[posb[a[i]]]]]) > 0)
continue;
swp(i, posb[a[i]]);
break;
}
if (i == n + 1)
{
n = 0;
break;
}
}
if (n == 0)
{
cout << "-1\n";
continue;
}
cout << ans.size() << '\n';
for (auto &ansi : ans)
{
if(ansi.first>ansi.second) swap(ansi.first,ansi.second);
cout << ansi.first << ' ' << ansi.second << '\n';
}
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3476kb
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: 3784kb
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 8 3 10 2 3 4 5 4 9 3 6 3 4 1 7 7 8 -1 -1 -1 -1 -1 -1 0 -1 -1 -1 3 1 2 1 6 4 5 -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 2 5 3 6 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...
result:
wrong answer Case #3: Jury has the answer but participant has not