QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#301428 | #7956. Walk Swapping | Heltion# | WA | 0ms | 3772kb | C++20 | 1.3kb | 2024-01-09 20:58:33 | 2024-01-09 20:58:33 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#ifndef ONLINE_JUDGE
#include "debug.h"
#else
#define debug(...) 417
#endif
using i64 = int64_t;
using u32 = uint32_t;
using u64 = uint64_t;
using f64 = double_t;
using i128 = __int128_t;
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
cout << fixed << setprecision(20);
int n;
cin >> n;
vector<int> a(n), b(n);
for (int& ai : a) { cin >> ai; }
for (int& bi : b) { cin >> bi; }
map<int, int> mp;
for (int i = 0; i < n; i += 1) {
mp[a[i]] += 1;
mp[b[i]] -= 1;
}
for (auto [x, y] : mp) {
if (y) {
cout << "-1";
return 0;
}
}
int ans = -1;
auto f = [&](vector<int> a, vector<int> b) {
for (int i = 0; i < n; i += 1) {
vector<int> d;
for (int j = 0; j < n; j += 1) {
if (a[j] != b[j]) { d.push_back(j); }
}
int pans = -1;
if (d.size() == 0) { pans = i * (n - 1); }
if (d.size() == 2) {
int k = d[1] - d[0];
pans = i * (n - 1) + min(k, n - k);
}
if (pans != -1) {
if (ans == -1 or ans > pans) { ans = pans; }
}
ranges::rotate(a, a.begin() + 1);
}
};
f(a, b);
ranges::reverse(a);
ranges::reverse(b);
f(a, b);
cout << ans;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3544kb
input:
4 4 3 2 1 3 4 2 1
output:
1
result:
ok single line: '1'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3612kb
input:
6 2 1 1 2 2 1 1 2 2 2 1 1
output:
7
result:
ok single line: '7'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3772kb
input:
6 4 1 3 6 2 5 6 2 1 3 4 5
output:
-1
result:
ok single line: '-1'
Test #4:
score: -100
Wrong Answer
time: 0ms
memory: 3596kb
input:
4 1 2 3 4 4 2 1 3
output:
4
result:
wrong answer 1st lines differ - expected: '2', found: '4'