63482023-11-22 16:23:51Tina0731Áruszállítás üres szakaszaicpp14Time limit exceeded 29/50400ms4664 KiB
#include <iostream>
#include <bits/stdc++.h>

/*
10 4
8 9
5 8
1 3
3 4

7 4
1 2
1 5
6 7
2 3

15 7
2 6
1 3
4 5
8 10
12 14
7 9
1 4

15 4
3 10
4 11
13 14
2 3
*/

using namespace std;

int main()
{
    pair<int, int> x; //x.first, x.second
    vector<pair<int, int>> parok;

    map<int, int> m;
    int h, n;
    int k, b;
    bool ujkell=true;
    cin>>h>>n;
    for(int i=0;i<n;i++)
    {
        ujkell=true;
        cin>>x.first>>x.second;
        for(int j=0;j<parok.size();j++)
        {
            if(parok.at(j).first<=x.first && parok.at(j).second>=x.second)
            {
                ujkell=false;
                break;
            }
            else if(parok.at(j).first<=x.first && parok.at(j).second>=x.first)
            {
                ujkell=false;
                parok.at(j).second=x.second;
                break;
            }
            else if(parok.at(j).first<=x.second && parok.at(j).second>=x.second)
            {
                ujkell=false;
                parok.at(j).first=x.first;
                break;
            }
        }
        if(ujkell==true)
            parok.push_back(x);
    }

    sort(parok.begin(), parok.end());
    /*cout<<endl;
    for(pair<int,int> xx:parok)
        cout<<xx.first<<" "<<xx.second<<endl;*/


    if(!parok.empty())
    {
        int szamol=0;
        if(parok.at(0).first>1)
            szamol=1;
        for(int j=1;j<parok.size();j++)
        {
            if(parok.at(j-1).second<parok.at(j).first)
                szamol++;
        }
        if(parok.at(parok.size()-1).second<h)
            szamol++;
        cout<<szamol;
    }
    else
        cout<<0;




    return 0;
}
SubtaskSumTestVerdictTimeMemory
base29/50
1Accepted0/03ms1684 KiB
2Time limit exceeded0/0400ms1188 KiB
3Accepted2/23ms2116 KiB
4Accepted2/23ms2356 KiB
5Accepted2/22ms2448 KiB
6Accepted2/23ms2568 KiB
7Accepted2/22ms2656 KiB
8Accepted2/23ms2780 KiB
9Accepted2/23ms2944 KiB
10Accepted2/23ms3152 KiB
11Accepted2/23ms3392 KiB
12Accepted2/23ms3460 KiB
13Wrong answer0/332ms3552 KiB
14Wrong answer0/390ms3860 KiB
15Wrong answer0/341ms3920 KiB
16Accepted3/359ms4056 KiB
17Accepted3/361ms4392 KiB
18Accepted3/368ms4664 KiB
19Wrong answer0/343ms4444 KiB
20Wrong answer0/372ms4512 KiB
21Time limit exceeded0/3365ms3736 KiB
22Time limit exceeded0/3372ms3676 KiB