172152025-06-03 16:23:04ercseferencSzimmetrikus sorozatcpp17Runtime error 48/100314ms131072 KiB
#include <bits/stdc++.h>
using namespace std;

struct par {
    int a, b;
};

struct adatszam {
    int ert, ind, csop;
};

bool has1(adatszam m, adatszam n) {
    return m.ert < n.ert;
}

bool has2(adatszam m, adatszam n) {
    return m.ind < n.ind;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    vector<par> b;
    int n;
    cin >> n;
    vector<adatszam> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i].ert;
        a[i].ind = i;
    }

    vector<vector<int>> csoportok;
    int t = 0;

    if (n > 0) {
        sort(a.begin(), a.end(), has1);
        csoportok.push_back(vector<int>());
        csoportok[0].push_back(a[0].ind);
        a[0].csop = 0;

        for (int i = 1; i < n; i++) {
            if (a[i].ert != a[i-1].ert) {
                t++;
                csoportok.push_back(vector<int>());
            }
            csoportok[t].push_back(a[i].ind);
            a[i].csop = t;
        }
    }

    sort(a.begin(), a.end(), has2);

    for (int i = 0; i < n/2; i++) {
        if (a[i].ert != a[n-i-1].ert) {
            int x, y;
            if (a[i].ert > a[n-i-1].ert) {
                x = n-i-1;
                y = i;
            } else {
                x = i;
                y = n-i-1;
            }
            par q;
            q.a = a[y].ert;
            q.b = a[x].ert;
            b.push_back(q);

            int w = a[y].csop;
            if (w != a[x].csop) {
                int target_group = a[x].csop;
                int size_w = csoportok[w].size();
                for (int j = 0; j < size_w; j++) {
                    int idx = csoportok[w][j];
                    a[idx].ert = a[x].ert;
                    a[idx].csop = target_group;
                    csoportok[target_group].push_back(idx);
                }
                csoportok[w].clear();
            }
        }
    }

    cout << b.size() << endl;
    for (int i = 0; i < b.size(); i++) {
        cout << b[i].a << " " << b[i].b << endl;
    }

    return 0;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted1ms316 KiB
2Accepted115ms7144 KiB
subtask29/9
3Accepted2ms316 KiB
4Accepted2ms316 KiB
5Accepted2ms316 KiB
6Accepted2ms508 KiB
7Accepted1ms456 KiB
subtask314/14
8Accepted1ms316 KiB
9Accepted1ms356 KiB
10Accepted1ms316 KiB
11Accepted1ms316 KiB
12Accepted1ms500 KiB
13Accepted1ms544 KiB
subtask425/25
14Accepted1ms316 KiB
15Accepted2ms316 KiB
16Accepted4ms564 KiB
17Accepted4ms564 KiB
18Accepted4ms564 KiB
19Accepted3ms564 KiB
20Accepted3ms564 KiB
21Accepted2ms316 KiB
subtask50/22
22Accepted180ms9704 KiB
23Runtime error314ms131072 KiB
24Accepted254ms12000 KiB
25Accepted185ms9696 KiB
26Accepted171ms9696 KiB
27Runtime error294ms131072 KiB
28Accepted240ms13968 KiB
29Accepted171ms9608 KiB
30Accepted166ms9696 KiB
31Runtime error298ms131072 KiB
32Accepted254ms15328 KiB
33Accepted189ms9612 KiB
34Accepted179ms9612 KiB
35Runtime error296ms131072 KiB
36Accepted241ms16608 KiB
37Accepted172ms9684 KiB
subtask60/30
38Accepted1ms320 KiB
39Accepted123ms7144 KiB
40Accepted2ms316 KiB
41Accepted2ms316 KiB
42Accepted2ms316 KiB
43Accepted2ms508 KiB
44Accepted1ms456 KiB
45Accepted1ms316 KiB
46Accepted1ms356 KiB
47Accepted1ms316 KiB
48Accepted1ms316 KiB
49Accepted1ms500 KiB
50Accepted1ms544 KiB
51Accepted1ms316 KiB
52Accepted2ms316 KiB
53Accepted4ms564 KiB
54Accepted4ms564 KiB
55Accepted4ms564 KiB
56Accepted3ms564 KiB
57Accepted3ms564 KiB
58Accepted2ms316 KiB
59Accepted180ms9704 KiB
60Runtime error314ms131072 KiB
61Accepted254ms12000 KiB
62Accepted185ms9696 KiB
63Accepted171ms9696 KiB
64Runtime error294ms131072 KiB
65Accepted240ms13968 KiB
66Accepted171ms9608 KiB
67Accepted166ms9696 KiB
68Runtime error298ms131072 KiB
69Accepted254ms15328 KiB
70Accepted189ms9612 KiB
71Accepted179ms9612 KiB
72Runtime error296ms131072 KiB
73Accepted241ms16608 KiB
74Accepted172ms9684 KiB
75Accepted275ms13924 KiB
76Accepted180ms10984 KiB
77Accepted87ms5036 KiB
78Accepted180ms12264 KiB
79Accepted128ms10972 KiB
80Accepted93ms7912 KiB
81Accepted93ms7912 KiB
82Accepted96ms7912 KiB
83Accepted291ms14560 KiB
84Accepted93ms5292 KiB
85Accepted129ms11040 KiB
86Accepted100ms8264 KiB
87Accepted101ms8160 KiB
88Accepted101ms8264 KiB
89Accepted101ms8276 KiB