Submission #754572

#TimeUsernameProblemLanguageResultExecution timeMemory
754572StickfishCat (info1cup19_cat)C++17
36.25 / 100
901 ms17064 KiB
#include <iostream> #include <vector> using namespace std; vector<pair<int, int>> sort_ops(vector<int> p) { int n = p.size(); vector<int> rp(n); for (int i = 0; i < n; ++i) rp[p[i]] = i; vector<pair<int, int>> ans; for (int t = 0; t < n; ++t) { if (p[t] == t) continue; int i = rp[t]; ans.push_back({t, i}); swap(p[i], p[t]); rp[p[t]] = t; rp[p[i]] = i; } return ans; } void solve() { int n; cin >> n; vector<int> p(n); for (int i = 0; i < n; ++i) cin >> p[i], --p[i]; for (int i = 0; i < n; ++i) if (p[i] + p[n - i - 1] != n - 1) { cout << "-1\n"; return; } int e1 = 0; for (int i = 0; i < n / 2; ++i) e1 += p[i] >= n / 2; if (e1 % 2) { cout << "-1\n"; return; } if (e1 == 0) { vector<int> p0(n / 2); for (int i = 0; i < n / 2; ++i) p0[i] = p[i]; vector<pair<int, int>> ans = sort_ops(p0); cout << ans.size() << ' ' << ans.size() << '\n'; for (auto x : ans) cout << x.first + 1 << ' ' << x.second + 1 << '\n'; return; } cout << "1 1\n"; cout << "1 2\n"; } signed main() { int t; cin >> t; while (t--) { solve(); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...