Submission #1331403

#TimeUsernameProblemLanguageResultExecution timeMemory
1331403AndreyPavlovA String Problem (EGOI25_stringproblem)C++20
30 / 100
2108 ms254104 KiB
#include <iostream>
#include <vector>
#include <numeric>

using namespace std;
using pii = pair<int,int>;

template <class T>
bool chmax (T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

int main() {
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector <int> cnt(2 * n);
    vector <pair <int, int>> a(n);
    vector <int> who(2 * n);
    for (int i = 0; i < n; ++i) {
        int u, v;
        cin >> u >> v;
        if (u > v) {
            swap(u, v);
        }
        a[i] = {u, v};
        who[u] = who[v] = i;
        cnt[(u + v) % (2 * n)]++;
    }
    int res = 0;
    int j = -1;
    for (int i = 1; i < 2 * n; i += 2) {
        if (chmax(res, cnt[i])) {
            j = i;
        }
    }
    cout << n - res << '\n';
    for (int i = 0; i < n; ++i) {
        int cur = i;
        while (true) {
            if ((a[cur].first + a[cur].second) % (2 * n) == j) {
                break;
            }
            int k = (j + 2 * n - a[cur].first) % (2 * n);
            cout << cur << ' ' << a[cur].second << ' ' << k << '\n';
            a[cur].second = k;
            int to = who[k];
            if (a[to].first == k) {
                swap(a[to].first, a[to].second);
            }
            cur = to;
        }
    }
    return 0;
}
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...