3155 | 2023-02-20 23:02:40 | Ancsa | Zsonglőrködés | cpp11 | Time limit exceeded 35/100 | 1.6s | 6924 KiB |
#include <bits/stdc++.h>
using namespace std;
typedef struct{
int e;
int v;
//bool volte=false;
} Interv;
/*
5
1 5
4 5
5 8
5 9
1 9
*/
/*
9
1 3
2 4
8 10
1 7
2 7
2 3
9 11
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;
cout<<endl;
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);
/*
for(Interv x: musor)
cout<<x.e<<"-"<<x.v<<endl;
*/
queue <Interv> sor;
Interv jelol;
jelol.e=-1;
jelol.v=-1;
for(Interv x: musor)
{
sor.push(x);
}
Interv most, uj;
uj=jelol;
sor.push(uj);
int szamlal=0;
while(sor.size()>1)
{
if (uj.e==-1)
{
most=sor.front();
sor.pop();
//cout<<endl<<most.e<<"--"<<most.v<<" ";
szamlal++;
}
else
{
most=uj;
}
//qkiir(sor);
uj=sor.front();
//cout<<uj.e<<"**"<<uj.v<<" ";
sor.pop();
while(most.v>uj.e && uj.e!=-1)
{
sor.push(uj);
uj=sor.front();
sor.pop();
//qkiir(sor);
}
if(most.v==uj.e)
{
//cout<<uj.e<<"--"<<uj.v<<" ";
//most=uj;
//most=uj;
//sor.pop();
//uj=sor.front();
//qkiir(sor);
}
else if (most.v<uj.e )
while(uj.e!=-1)
{
sor.push(uj);
uj=sor.front();
sor.pop();
}
if(uj.e==-1)
{
sor.push(uj);
}
}
cout << szamlal << endl;
return 0;
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 3ms | 1688 KiB | ||||
2 | Accepted | 3ms | 1848 KiB | ||||
subtask2 | 0/20 | ||||||
3 | Accepted | 12ms | 2088 KiB | ||||
4 | Time limit exceeded | 1.57s | 2628 KiB | ||||
5 | Time limit exceeded | 1.578s | 4212 KiB | ||||
6 | Time limit exceeded | 1.578s | 4780 KiB | ||||
7 | Time limit exceeded | 1.555s | 5096 KiB | ||||
8 | Time limit exceeded | 1.58s | 5400 KiB | ||||
9 | Time limit exceeded | 1.583s | 5408 KiB | ||||
10 | Time limit exceeded | 1.562s | 5488 KiB | ||||
11 | Time limit exceeded | 1.564s | 5476 KiB | ||||
subtask3 | 35/35 | ||||||
12 | Accepted | 3ms | 3148 KiB | ||||
13 | Accepted | 3ms | 3144 KiB | ||||
14 | Accepted | 3ms | 3120 KiB | ||||
15 | Accepted | 3ms | 3252 KiB | ||||
16 | Accepted | 4ms | 3468 KiB | ||||
17 | Accepted | 4ms | 3572 KiB | ||||
18 | Accepted | 4ms | 3576 KiB | ||||
19 | Accepted | 4ms | 3788 KiB | ||||
20 | Accepted | 4ms | 4048 KiB | ||||
subtask4 | 0/45 | ||||||
21 | Accepted | 13ms | 4184 KiB | ||||
22 | Time limit exceeded | 1.6s | 4420 KiB | ||||
23 | Time limit exceeded | 1.536s | 5968 KiB | ||||
24 | Time limit exceeded | 1.552s | 6488 KiB | ||||
25 | Time limit exceeded | 1.531s | 6876 KiB | ||||
26 | Time limit exceeded | 1.564s | 6872 KiB | ||||
27 | Time limit exceeded | 1.565s | 6924 KiB | ||||
28 | Time limit exceeded | 1.56s | 6804 KiB | ||||
29 | Time limit exceeded | 1.585s | 6920 KiB |