Submission #950280

# Submission time Handle Problem Language Result Execution time Memory
950280 2024-03-20T07:37:06 Z Pring Cat (info1cup19_cat) C++17
25 / 100
289 ms 13252 KB
#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;

void SORT() {
    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]]);
        }
    }
}

void COUT() {
    cout << ans.size() << ' ' << ans.size() << '\n';
    for (auto &i : ans) cout << i.fs << ' ' << i.sc << '\n';
}

namespace SB24 {

    void solve() {
        SORT();
        COUT();
    }
}

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]]);
    }
    SORT();
    COUT();
}

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

cat.cpp: In function 'void solve()':
cat.cpp:51: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]
   51 |     for (int i = 0; i < w.size(); i += 2) {
      |                     ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 344 KB Wrong answer
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 17 ms 604 KB Output is correct
2 Correct 14 ms 660 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 344 KB Wrong answer
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 17 ms 604 KB Output is correct
2 Correct 14 ms 660 KB Output is correct
3 Correct 278 ms 10824 KB Output is correct
4 Correct 264 ms 10340 KB Output is correct
5 Correct 289 ms 13252 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 344 KB Wrong answer
2 Halted 0 ms 0 KB -