Submission #950263

#TimeUsernameProblemLanguageResultExecution timeMemory
950263PringCat (info1cup19_cat)C++17
25 / 100
328 ms27108 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define fs first #define sc second #define mp make_pair #define FOR(i, j, k) for (int i = j, Z = k; i < Z; i++) typedef pair<int, int> pii; const int MXN = 200005; int N, p[MXN]; int n; vector<pii> ans; namespace SB24 { void solve() { FOR(i, 1, n + 1) { if (p[i] == i) continue; while (p[i] != i) { ans.emplace_back(i, p[i]); swap(p[i], p[p[i]]); } } cout << ans.size() << ' ' << ans.size() << '\n'; for (auto &i : ans) cout << i.fs << ' ' << i.sc << '\n'; } } void solve() { vector<int> w; FOR(i, 1, n + 1) { if (p[i] > p[N - i + 1]) { w.push_back(i); swap(p[i], p[N - i + 1]); } } if (w.size() % 2) { cout << -1 << '\n'; return; } for (int i = 0; i < w.size(); i += 2) { ans.emplace_back(w[i], N - w[i + 1] + 1); swap(p[w[i]], p[w[i + 1]]); } FOR(i, 1, n + 1) { if (p[i] == i) continue; while (p[i] != i) { ans.emplace_back(i, p[i]); swap(p[i], p[p[i]]); } } cout << ans.size() << ' ' << ans.size() << '\n'; for (auto &i : ans) cout << i.fs << ' ' << i.sc << '\n'; } void miku() { cin >> N; n = N / 2; FOR(i, 1, N + 1) cin >> p[i]; FOR(i, 1, n + 1) { if (p[i] + p[N - i + 1] != N + 1) { cout << -1 << '\n'; return; } } if (*max_element(p, p + n) <= n) { SB24::solve(); return; } solve(); } void RESET() { ans.clear(); } int32_t main() { cin.tie(0) -> sync_with_stdio(false); cin.exceptions(cin.failbit); int t; cin >> t; while (t--) { miku(); RESET(); } return 0; }

Compilation message (stderr)

cat.cpp: In function 'void solve()':
cat.cpp:43:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |     for (int i = 0; i < w.size(); i += 2) {
      |                     ~~^~~~~~~~~~
#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...