# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
315326 | Kevin_Zhang_TW | Cat (info1cup19_cat) | C++17 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define pb emplace_back
#define AI(i) begin(i), end(i)
using namespace std;
using ll = long long;
#ifdef KEV
#define DE(args...) kout("[ " + string(#args) + " ] = ", args)
void kout() {cerr << endl;}
template<class T1, class ...T2>
void kout (T1 v, T2 ...e) { cerr << v << ' ', kout(e...); }
template<class T>
void debug(T L, T R) { while (L != R) cerr << *L << " \n"[next(L)==R], ++L; }
#else
#define DE(...) 0
#define debug(...) 0
#endif
const int MAX_N = 300010;
int n;
vector<pair<int,int>> op;
// just the front half
void swap_sort(vector<int> p) {
}
bool valid(vector<int> p) {
int cnt = 0, m = n / 2;
for (int l = 0, r = n-1;l < r;++l, --r) {
if ((p[l]>m) ^ (p[r]<=m))
return false;
if (p[l] > m)
++cnt;
}
if (cnt & 1)
return false;
vector<int> pos(n);
for (int i = 0;i < n;++i)
pos[ p[i] ] = i;
auto sw = [&](int x, int y) {
swap(p[x], p[y]), swap(pos[ p[x] ], pos[ p[y] ]);
};
auto do_op = [&](int x, int y) {
int a = x, b = y, c = n - x - 1, d = n - y - 1;
sw(a, b), sw(c, d);
};
for (int i = 0;i < m;++i) {
while (i+1 != p[i])
do_op(i, p[i]);
}
for (int i = 0;i < n;++i)
if (p[i] != i+1)
return false;
return true;
}
// make p good enough so that I can do swap sort on it
void pair_good(vector<int> &p) {
}
bool solve() {
cin >> n;
vector<int> p(n);
for (int &i : p)
cin >> i;
if (!valid(p))
return false;
pair_good(p);
swap_sort(p);
return true;
}
signed main() {
ios_base::sync_with_stdio(0), cin.tie(0);
int T;
cin >> T;
while (T--) {
op.clear();
if (!solve())
cout << -1 << '\n';
else {
cout << op.size() << ' ' << op.size() << '\n';
for (auto [a, b] : op)
cout << a+1 << ' ' << b+1 << '\n';
}
}
}
#include<bits/stdc++.h>
#define pb emplace_back
#define AI(i) begin(i), end(i)
using namespace std;
using ll = long long;
#ifdef KEV
#define DE(args...) kout("[ " + string(#args) + " ] = ", args)
void kout() {cerr << endl;}
template<class T1, class ...T2>
void kout (T1 v, T2 ...e) { cerr << v << ' ', kout(e...); }
template<class T>
void debug(T L, T R) { while (L != R) cerr << *L << " \n"[next(L)==R], ++L; }
#else
#define DE(...) 0
#define debug(...) 0
#endif
const int MAX_N = 300010;
int n;
vector<pair<int,int>> op;
// just the front half
void swap_sort(vector<int> p) {
}
bool valid(vector<int> p) {
int cnt = 0, m = n / 2;
for (int l = 0, r = n-1;l < r;++l, --r) {
if ((p[l]>m) ^ (p[r]<=m))
return false;
if (p[l] > m)
++cnt;
}
if (cnt & 1)
return false;
vector<int> pos(n);
for (int i = 0;i < n;++i)
pos[ p[i] ] = i;
auto sw = [&](int x, int y) {
swap(p[x], p[y]), swap(pos[ p[x] ], pos[ p[y] ]);
};
auto do_op = [&](int x, int y) {
int a = x, b = y, c = n - x - 1, d = n - y - 1;
sw(a, b), sw(c, d);
};
for (int i = 0;i < m;++i) {
while (i+1 != p[i])
do_op(i, p[i]);
}
for (int i = 0;i < n;++i)
if (p[i] != i+1)
return false;
return true;
}
// make p good enough so that I can do swap sort on it
void pair_good(vector<int> &p) {
}
bool solve() {
cin >> n;
vector<int> p(n);
for (int &i : p)
cin >> i;
if (!valid(p))
return false;
pair_good(p);
swap_sort(p);
return true;
}
signed main() {
ios_base::sync_with_stdio(0), cin.tie(0);
int T;
cin >> T;
while (T--) {
op.clear();
if (!solve())
cout << -1 << '\n';
else {
cout << op.size() << ' ' << op.size() << '\n';
for (auto [a, b] : op)
cout << a+1 << ' ' << b+1 << '\n';
}
}
}