23122023-01-10 10:40:57rennRobotokcpp11Runtime error 22/5037ms61500 KiB
#include <bits/stdc++.h>
using namespace std;

#define InTheNameOfGod cin.tie(0); ios::sync_with_stdio(0);

int gyujtes(vector<stack<int>> &mezo, int i, int j, int &temp)
{
    //cout << i << " " << j << "\n";
    if(i == mezo.size()) return 0;
    if(mezo[i].empty()) return gyujtes(mezo, ++i, j, temp);
    if(mezo[i].top() < j) return gyujtes(mezo, ++i, j, temp);

    temp = mezo[i].top();

    while (!mezo[i].empty() && mezo[i].top() >= j)
    {
        //cout << "kiszed " << i << " " << mezo[i].top() << "\n";
        mezo[i].pop();
    }

    j = temp;
    ////cout << "xdxd\n";
    return gyujtes(mezo, ++i, j, temp);
}

int main()
{
    InTheNameOfGod

    int sor, oszlop, pont;
    cin >> sor >> oszlop >> pont;

    vector<set<int>> mezo1(sor);
    vector<stack<int>> mezo2(sor);

    for (size_t i = 0, a, b; i < pont; i++)
    {
        cin >> a >> b;
        mezo1[a-1].insert(b-1);
    }

    //cout << "1\n";

    for (size_t i = 0; i < sor; i++)
    {
        for(auto j : mezo1[i])
            mezo2[i].push(j);
    }

    //cout << "2\n";

    int robotok = 0;

    for(int i = 0; i < sor; i++)
    {
        //cout << "3\n";
        if(mezo2[i].empty()) continue;
        int legtav = 0;
        int temp;
        robotok++;
        //cout << "sor " << i << '\n';
        for(int j = i; j < sor; j++) {
            if(mezo2[j].empty()) continue;
            if(mezo2[j].top() < legtav) continue;
            temp = mezo2[j].top();
            while(!mezo2[j].empty() && mezo2[j].top() >= legtav){
                //cout << i << " " << mezo2[j].top() << 
                mezo2[j].pop();
            }
            legtav = temp;
        }

        //cout << "v\n";
    }

    cout << robotok << "\n";
    
}
SubtaskSumTestVerdictTimeMemory
base22/50
1Accepted0/03ms1976 KiB
2Runtime error0/026ms50732 KiB
3Accepted2/22ms2184 KiB
4Accepted2/22ms2460 KiB
5Accepted2/22ms2660 KiB
6Accepted2/24ms3080 KiB
7Accepted2/24ms3328 KiB
8Accepted2/23ms4604 KiB
9Accepted2/23ms4520 KiB
10Accepted2/23ms4516 KiB
11Accepted2/28ms5248 KiB
12Accepted2/227ms8940 KiB
13Accepted2/29ms17392 KiB
14Runtime error0/229ms51668 KiB
15Runtime error0/230ms51860 KiB
16Runtime error0/237ms61500 KiB
17Runtime error0/425ms51808 KiB
18Runtime error0/625ms52064 KiB
19Runtime error0/625ms52264 KiB
20Runtime error0/630ms52324 KiB