# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
687059 | Alihan_8 | Cat (info1cup19_cat) | C++17 | 569 ms | 29604 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
// include <ext/pb_ds/assoc_container.hpp>
// include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
using namespace std;
#define all(x) x.begin(), x.end()
#define pb push_back
// define ordered_set tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>
#define mpr make_pair
#define ln '\n'
void IO(string name){freopen((name+".in").c_str(),"r",stdin); freopen((name+".out").c_str(),"w",stdout);}
#define int long long
void solve(){
int n; cin >> n;
vector <int> p(n), pos(n);
for ( auto &i: p ) cin >> i, i--;
vector <pair<int,int>> res;
auto inv = [&](int i){
return n-1-i;
};
auto answer = [&](int i, int j){
int _i = inv(i), _j = inv(j);
swap(p[i], p[j]), swap(pos[p[i]], pos[p[j]]);
swap(p[_i], p[_j]), swap(pos[p[_i]], pos[p[_j]]);
res.pb({i, j});
};
auto print = [&](){
cout << (int)res.size() << ' ' << (int)res.size() << ln;
for ( auto [l, r]: res ) cout << ++l << ' ' << ++r << ln;
};
for ( int i = 0; i < n; i++ ) pos[p[i]] = i;
vector <int> rem;
for ( int i = 0; i < n/2; i++ ){
if ( pos[i] == i ) continue;
if ( inv(pos[i]) < i ){
cout << "-1\n";
return;
}
if ( inv(i) == pos[i] ){
rem.pb(i);
continue;
}
answer(i, pos[i]);
}
if ( (int)rem.size() & 1 ){
cout << "-1\n";
return;
}
for ( int i = 1; i < (int)rem.size(); i += 2 ){
answer(rem[i], inv(rem[i-1]));
answer(rem[i], rem[i-1]);
}
for ( int i = 0; i < n; i++ ){
if ( pos[i] != i ){
cout << "-1\n";
return;
}
}
print();
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int T; cin >> T;
while ( T-- ){
solve();
}
cout << '\n';
}
Compilation message (stderr)
# | 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... |