29982023-02-07 17:09:22Tina0731Zsonglőrködéscpp11Time limit exceeded 35/1001.6s8724 KiB
#include <iostream>
#include <bits/stdc++.h>

using namespace std;

typedef struct
{
    int e;
    int v;
    bool volte=false;
}Interv;

/*
9
1 3
8 10
1 7
2 7
2 3
9 11
2 4
3 9
3 8
*/

bool eszerint(Interv i1, Interv i2)
{
    if(i1.e!=i2.e)
        return i1.e<i2.e;
    else
        return i1.v<i2.v;
}

void qkiir(queue<Interv> q)
{
    queue<Interv> seged=q;
    Interv v;
    while(!seged.empty())
    {
        v=seged.front();
        cout<<v.e<<". ."<<v.v<<" ";
        seged.pop();
    }
    cout<<endl;
}

int main()
{
    int n;
    cin>>n;
    vector<Interv> musor(n);

    for(int i=0;i<n;i++)
    {
        cin>>musor.at(i).e>>musor.at(i).v;
    }

    /*for(Interv x : musor)
        cout<<x.e<<"-"<<x.v<<" ";
    cout<<endl;*/

    sort(musor.begin(),musor.end(), eszerint);
    //cout<<endl;
    /*for(Interv x : musor)
        cout<<x.e<<"-"<<x.v<<endl;
    cout<<endl;*/


    queue<Interv> sor;
    Interv jelol;
    jelol.e=-1;
    jelol.v=-1;

    for(Interv x : musor)
    {
        sor.push(x);

    }
    sor.push(jelol);
    //qkiir(sor);

    /*while(sor.size()>1)
    {
        Interv most;
        most=sor.front();
        cout<<most.e<<"--"<<most.v<<" ";
        sor.pop();
        Interv uj=sor.front();
        while(most.v<uj.e && uj.e!=-1)
        {
            sor.push(uj);
            sor.pop();
            uj=sor.front();
            qkiir(sor);
        }
        if(most.v==uj.e)
        {
            cout<<uj.e<<"--"<<uj.v<<" ";
            most=uj;
            sor.pop();
            uj=sor.front();
            qkiir(sor);
        }
        else if (uj.e==-1)
        {
            sor.pop();
            sor.push(uj);
            //most=sor.front();
            qkiir(sor);
        }

    }*/

    //Interv seged;
    int szamol=0;
    while(sor.size()>1)
    {
        Interv most;
        most=sor.front();
        //cout<<most.e<<"--"<<most.v<<" ";
        sor.pop();
        //Interv uj=sor.front();
        //cout<<most.e<<" "<<most.v<<" --> ";
        while(sor.front().e!=-1)
        {
            if(most.v==sor.front().e)
            {
                most=sor.front();
                sor.pop();
                //cout<<most.e<<" "<<most.v<<" --> ";
            }
            else
            {
                sor.push(sor.front());
                sor.pop();

            }
        }
        //cout<<endl;
        szamol++;
        sor.push(sor.front());
        sor.pop();

    }
    cout<<szamol;


    return 0;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1816 KiB
2Accepted3ms2056 KiB
subtask20/20
3Accepted13ms2436 KiB
4Time limit exceeded1.536s3400 KiB
5Time limit exceeded1.549s5632 KiB
6Time limit exceeded1.544s6604 KiB
7Time limit exceeded1.575s6940 KiB
8Time limit exceeded1.585s7264 KiB
9Time limit exceeded1.572s7464 KiB
10Time limit exceeded1.559s7600 KiB
11Time limit exceeded1.567s7608 KiB
subtask335/35
12Accepted3ms3568 KiB
13Accepted3ms3572 KiB
14Accepted3ms3708 KiB
15Accepted3ms3952 KiB
16Accepted4ms3880 KiB
17Accepted4ms3968 KiB
18Accepted4ms4004 KiB
19Accepted4ms4232 KiB
20Accepted4ms4192 KiB
subtask40/45
21Accepted13ms4464 KiB
22Time limit exceeded1.6s5328 KiB
23Time limit exceeded1.569s7540 KiB
24Time limit exceeded1.567s8284 KiB
25Time limit exceeded1.575s8724 KiB
26Time limit exceeded1.537s8592 KiB
27Time limit exceeded1.555s8600 KiB
28Time limit exceeded1.547s8660 KiB
29Time limit exceeded1.564s8660 KiB