# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
950263 |
2024-03-20T07:27:56 Z |
Pring |
Cat (info1cup19_cat) |
C++17 |
|
328 ms |
27108 KB |
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define fs first
#define sc second
#define mp make_pair
#define FOR(i, j, k) for (int i = j, Z = k; i < Z; i++)
typedef pair<int, int> pii;
const int MXN = 200005;
int N, p[MXN];
int n;
vector<pii> ans;
namespace SB24 {
void solve() {
FOR(i, 1, n + 1) {
if (p[i] == i) continue;
while (p[i] != i) {
ans.emplace_back(i, p[i]);
swap(p[i], p[p[i]]);
}
}
cout << ans.size() << ' ' << ans.size() << '\n';
for (auto &i : ans) cout << i.fs << ' ' << i.sc << '\n';
}
}
void solve() {
vector<int> w;
FOR(i, 1, n + 1) {
if (p[i] > p[N - i + 1]) {
w.push_back(i);
swap(p[i], p[N - i + 1]);
}
}
if (w.size() % 2) {
cout << -1 << '\n';
return;
}
for (int i = 0; i < w.size(); i += 2) {
ans.emplace_back(w[i], N - w[i + 1] + 1);
swap(p[w[i]], p[w[i + 1]]);
}
FOR(i, 1, n + 1) {
if (p[i] == i) continue;
while (p[i] != i) {
ans.emplace_back(i, p[i]);
swap(p[i], p[p[i]]);
}
}
cout << ans.size() << ' ' << ans.size() << '\n';
for (auto &i : ans) cout << i.fs << ' ' << i.sc << '\n';
}
void miku() {
cin >> N;
n = N / 2;
FOR(i, 1, N + 1) cin >> p[i];
FOR(i, 1, n + 1) {
if (p[i] + p[N - i + 1] != N + 1) {
cout << -1 << '\n';
return;
}
}
if (*max_element(p, p + n) <= n) {
SB24::solve();
return;
}
solve();
}
void RESET() {
ans.clear();
}
int32_t main() {
cin.tie(0) -> sync_with_stdio(false);
cin.exceptions(cin.failbit);
int t;
cin >> t;
while (t--) {
miku();
RESET();
}
return 0;
}
Compilation message
cat.cpp: In function 'void solve()':
cat.cpp:43:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
43 | for (int i = 0; i < w.size(); i += 2) {
| ~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
344 KB |
Wrong answer |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
604 KB |
Output is correct |
2 |
Correct |
13 ms |
1112 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
344 KB |
Wrong answer |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
604 KB |
Output is correct |
2 |
Correct |
13 ms |
1112 KB |
Output is correct |
3 |
Correct |
292 ms |
25368 KB |
Output is correct |
4 |
Correct |
299 ms |
25132 KB |
Output is correct |
5 |
Correct |
328 ms |
27108 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
344 KB |
Wrong answer |
2 |
Halted |
0 ms |
0 KB |
- |