172002025-06-03 12:21:50ercseferencSzimmetrikus sorozatcpp17Runtime error 48/100296ms131072 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(a[i].ert!=a[i+1].ert && i!=n-1){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
4Accepted1ms316 KiB
5Accepted1ms504 KiB
6Accepted2ms508 KiB
7Accepted1ms316 KiB
subtask314/14
8Accepted1ms316 KiB
9Accepted1ms316 KiB
10Accepted1ms316 KiB
11Accepted1ms316 KiB
12Accepted1ms316 KiB
13Accepted1ms520 KiB
subtask425/25
14Accepted1ms500 KiB
15Accepted2ms316 KiB
16Accepted4ms564 KiB
17Accepted4ms568 KiB
18Accepted4ms564 KiB
19Accepted3ms564 KiB
20Accepted3ms568 KiB
21Accepted2ms500 KiB
subtask50/22
22Accepted180ms9620 KiB
23Runtime error293ms131072 KiB
24Accepted256ms11920 KiB
25Accepted184ms9692 KiB
26Accepted171ms9696 KiB
27Runtime error287ms131072 KiB
28Accepted244ms13792 KiB
29Accepted173ms9696 KiB
30Accepted168ms9612 KiB
31Runtime error296ms131072 KiB
32Accepted254ms15328 KiB
33Accepted187ms9692 KiB
34Accepted181ms9688 KiB
35Runtime error291ms131072 KiB
36Accepted256ms16608 KiB
37Accepted184ms9696 KiB
subtask60/30
38Accepted1ms316 KiB
39Accepted123ms7144 KiB
40Accepted2ms316 KiB
41Accepted1ms316 KiB
42Accepted1ms504 KiB
43Accepted2ms508 KiB
44Accepted1ms316 KiB
45Accepted1ms316 KiB
46Accepted1ms316 KiB
47Accepted1ms316 KiB
48Accepted1ms316 KiB
49Accepted1ms316 KiB
50Accepted1ms520 KiB
51Accepted1ms500 KiB
52Accepted2ms316 KiB
53Accepted4ms564 KiB
54Accepted4ms568 KiB
55Accepted4ms564 KiB
56Accepted3ms564 KiB
57Accepted3ms568 KiB
58Accepted2ms500 KiB
59Accepted180ms9620 KiB
60Runtime error293ms131072 KiB
61Accepted256ms11920 KiB
62Accepted184ms9692 KiB
63Accepted171ms9696 KiB
64Runtime error287ms131072 KiB
65Accepted244ms13792 KiB
66Accepted173ms9696 KiB
67Accepted168ms9612 KiB
68Runtime error296ms131072 KiB
69Accepted254ms15328 KiB
70Accepted187ms9692 KiB
71Accepted181ms9688 KiB
72Runtime error291ms131072 KiB
73Accepted256ms16608 KiB
74Accepted184ms9696 KiB
75Accepted287ms13788 KiB
76Accepted192ms10984 KiB
77Accepted93ms4948 KiB
78Accepted187ms12256 KiB
79Accepted133ms10792 KiB
80Accepted101ms7912 KiB
81Accepted101ms7828 KiB
82Accepted103ms7928 KiB
83Accepted284ms14560 KiB
84Accepted98ms5292 KiB
85Accepted140ms10968 KiB
86Accepted108ms8076 KiB
87Accepted105ms8160 KiB
88Accepted107ms8076 KiB
89Accepted107ms8072 KiB