172822025-06-17 11:48:07ercseferencSzimmetrikus sorozatcpp17Runtime error 48/100307ms131072 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,x,y; 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;
    sort(a.begin(),a.end(), has1);
    vector<int>ures; csoportok.push_back(ures);
   for(int i=0; i<n; i++){
        csoportok[t].push_back(a[i].ind);
        a[i].csop=t;
        if(i!=n-1){
            if(a[i].ert!=a[i+1].ert){
                t++;
                csoportok.push_back(ures);}}}
    sort(a.begin(),a.end(), has2);
    for(int i=0; i<n/2; i++){
        if(a[i].ert!=a[n-i-1].ert){
            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 v=csoportok[a[y].csop].size();
            int w=a[y].csop;
            for(int j=0; j<v; j++){
                csoportok[a[x].csop].push_back(csoportok[w][j]);
                a[csoportok[w][j]].ert=a[x].ert;
                a[csoportok[w][j]].csop=a[x].csop;}}}
    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
2Accepted119ms7144 KiB
subtask29/9
3Accepted2ms316 KiB
4Accepted2ms316 KiB
5Accepted2ms500 KiB
6Accepted2ms316 KiB
7Accepted2ms316 KiB
subtask314/14
8Accepted1ms316 KiB
9Accepted1ms316 KiB
10Accepted1ms316 KiB
11Accepted1ms500 KiB
12Accepted1ms316 KiB
13Accepted1ms316 KiB
subtask425/25
14Accepted1ms320 KiB
15Accepted2ms500 KiB
16Accepted4ms580 KiB
17Accepted4ms564 KiB
18Accepted4ms568 KiB
19Accepted3ms564 KiB
20Accepted3ms564 KiB
21Accepted2ms316 KiB
subtask50/22
22Accepted182ms9732 KiB
23Runtime error291ms131072 KiB
24Accepted263ms11916 KiB
25Accepted186ms9608 KiB
26Accepted175ms9696 KiB
27Runtime error307ms131072 KiB
28Accepted246ms13792 KiB
29Accepted175ms9696 KiB
30Accepted172ms9612 KiB
31Runtime error301ms131072 KiB
32Accepted263ms15504 KiB
33Accepted190ms9700 KiB
34Accepted180ms9608 KiB
35Runtime error303ms131072 KiB
36Accepted252ms16612 KiB
37Accepted179ms9692 KiB
subtask60/30
38Accepted1ms316 KiB
39Accepted128ms7144 KiB
40Accepted2ms316 KiB
41Accepted2ms316 KiB
42Accepted2ms500 KiB
43Accepted2ms316 KiB
44Accepted2ms316 KiB
45Accepted1ms316 KiB
46Accepted1ms316 KiB
47Accepted1ms316 KiB
48Accepted1ms500 KiB
49Accepted1ms316 KiB
50Accepted1ms316 KiB
51Accepted1ms320 KiB
52Accepted2ms500 KiB
53Accepted4ms580 KiB
54Accepted4ms564 KiB
55Accepted4ms568 KiB
56Accepted3ms564 KiB
57Accepted3ms564 KiB
58Accepted2ms316 KiB
59Accepted182ms9732 KiB
60Runtime error291ms131072 KiB
61Accepted263ms11916 KiB
62Accepted186ms9608 KiB
63Accepted175ms9696 KiB
64Runtime error307ms131072 KiB
65Accepted246ms13792 KiB
66Accepted175ms9696 KiB
67Accepted172ms9612 KiB
68Runtime error301ms131072 KiB
69Accepted263ms15504 KiB
70Accepted190ms9700 KiB
71Accepted180ms9608 KiB
72Runtime error303ms131072 KiB
73Accepted252ms16612 KiB
74Accepted179ms9692 KiB
75Accepted282ms13784 KiB
76Accepted187ms10896 KiB
77Accepted93ms4948 KiB
78Accepted187ms12264 KiB
79Accepted130ms10792 KiB
80Accepted101ms7912 KiB
81Accepted101ms7912 KiB
82Accepted101ms7832 KiB
83Accepted303ms14568 KiB
84Accepted104ms5292 KiB
85Accepted140ms10792 KiB
86Accepted108ms8160 KiB
87Accepted108ms8160 KiB
88Accepted108ms8160 KiB
89Accepted107ms8164 KiB