# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
687051 | 2023-01-26T05:36:41 Z | Alihan_8 | Cat (info1cup19_cat) | C++17 | 18 ms | 1108 KB |
#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]); } print(); } signed main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); int T; cin >> T; while ( T-- ){ solve(); } cout << '\n'; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 4 ms | 340 KB | Wrong answer |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 18 ms | 1108 KB | Wrong answer |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 4 ms | 340 KB | Wrong answer |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 18 ms | 1108 KB | Wrong answer |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 4 ms | 340 KB | Wrong answer |
2 | Halted | 0 ms | 0 KB | - |