182952025-10-17 21:37:59ercseferencSzimmetrikus sorozatcpp17Runtime error 48/100328ms131072 KiB
#include <bits/stdc++.h>
#define int long long
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;}
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.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-1; i++){
        csoportok[t].push_back(a[i].ind);
        a[i].csop=t;
        if(a[i].ert!=a[i+1].ert){
                t++;
                csoportok.push_back(ures);}}
    a[n-1].csop=t; csoportok[t].push_back(a[n-1].ind);
    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;
            int r=a[x].csop;
            int u=a[x].ert;
            if(w==r)return 0;
            for(int j=0; j<v; j++){
                csoportok[r].push_back(csoportok[w][j]);
                a[csoportok[w][j]].ert=u;
                a[csoportok[w][j]].csop=r;}
            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
2Accepted129ms10984 KiB
subtask29/9
3Accepted2ms756 KiB
4Accepted2ms564 KiB
5Accepted2ms564 KiB
6Accepted2ms756 KiB
7Accepted2ms564 KiB
subtask314/14
8Accepted1ms424 KiB
9Accepted1ms424 KiB
10Accepted1ms316 KiB
11Accepted1ms500 KiB
12Accepted1ms428 KiB
13Accepted1ms360 KiB
subtask425/25
14Accepted1ms316 KiB
15Accepted2ms528 KiB
16Accepted4ms564 KiB
17Accepted4ms564 KiB
18Accepted4ms756 KiB
19Accepted4ms568 KiB
20Accepted4ms696 KiB
21Accepted3ms564 KiB
subtask50/22
22Accepted208ms14508 KiB
23Runtime error287ms131072 KiB
24Accepted289ms17328 KiB
25Accepted226ms14380 KiB
26Accepted209ms14308 KiB
27Runtime error263ms131072 KiB
28Accepted272ms20708 KiB
29Accepted203ms14304 KiB
30Accepted195ms14400 KiB
31Runtime error282ms131072 KiB
32Accepted286ms24800 KiB
33Accepted218ms14564 KiB
34Accepted209ms14512 KiB
35Runtime error266ms131072 KiB
36Accepted279ms26852 KiB
37Accepted202ms14560 KiB
subtask60/30
38Accepted1ms316 KiB
39Accepted137ms10984 KiB
40Accepted2ms756 KiB
41Accepted2ms564 KiB
42Accepted2ms564 KiB
43Accepted2ms756 KiB
44Accepted2ms564 KiB
45Accepted1ms424 KiB
46Accepted1ms424 KiB
47Accepted1ms316 KiB
48Accepted1ms500 KiB
49Accepted1ms428 KiB
50Accepted1ms360 KiB
51Accepted1ms316 KiB
52Accepted2ms528 KiB
53Accepted4ms564 KiB
54Accepted4ms564 KiB
55Accepted4ms756 KiB
56Accepted4ms568 KiB
57Accepted4ms696 KiB
58Accepted3ms564 KiB
59Accepted208ms14508 KiB
60Runtime error287ms131072 KiB
61Accepted289ms17328 KiB
62Accepted226ms14380 KiB
63Accepted209ms14308 KiB
64Runtime error263ms131072 KiB
65Accepted272ms20708 KiB
66Accepted203ms14304 KiB
67Accepted195ms14400 KiB
68Runtime error282ms131072 KiB
69Accepted286ms24800 KiB
70Accepted218ms14564 KiB
71Accepted209ms14512 KiB
72Runtime error266ms131072 KiB
73Accepted279ms26852 KiB
74Accepted202ms14560 KiB
75Accepted328ms20736 KiB
76Accepted214ms18508 KiB
77Accepted115ms10100 KiB
78Accepted230ms22064 KiB
79Accepted163ms21984 KiB
80Accepted122ms11568 KiB
81Accepted122ms11748 KiB
82Accepted123ms11744 KiB
83Accepted312ms22244 KiB
84Accepted114ms10664 KiB
85Accepted177ms22752 KiB
86Accepted128ms12516 KiB
87Accepted126ms12772 KiB
88Accepted128ms12516 KiB
89Accepted127ms12452 KiB