이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
int a[200001];
int b[200001];
int n;
vector<pair<int, int>> ans;
void f(int i, int j){
ans.push_back({i, j});
swap(a[i], a[j]);
swap(b[a[i]], b[a[j]]);
swap(a[n + 1 - i], a[n + 1 - j]);
swap(b[a[n + 1 - i]], b[a[n + 1 - j]]);
}
void solve(){
ans.clear();
cin >> n; for(int i = 1; i <= n; i++) cin >> a[i];
for(int i = 1; i <= n / 2; i++){
if(a[i] + a[n + 1 - i] != n + 1){
cout << -1 << endl;
return;
}
}
for(int i = 1; i <= n; i++) b[a[i]] = i;
vector<int> oppo;
for(int i = 1; i <= n / 2; i++){
if(a[i] == i) continue;
else if(a[i] == n + 1 - i) oppo.push_back(i);
else f(i, b[i]);
}
if(oppo.size() % 2){
cout << -1 << endl;
return;
}
while(oppo.size() >= 2){
int v1 = oppo.back(); oppo.pop_back();
int v2 = oppo.back(); oppo.pop_back();
ans.push_back({v1, v2});
ans.push_back({v1, n + 1 - v2});
}
cout << ans.size() << ' ' << ans.size() << endl;
for(auto i : ans){
cout << i.first << ' ' << i.second << endl;
}
}
int main(){
cin.tie(0); cout.tie(0)->sync_with_stdio(false);
int t; cin >> t;
while(t--) solve();
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |