23102023-01-10 10:22:02rennRobotokcpp11Runtime error 22/5029ms61952 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, j, t, temp; i < sor; i++)
    {
        //cout << "3\n";
        if(mezo2[i].empty()) continue;

        robotok++;
        gyujtes(mezo2, (t=i), (j=0), temp);
        //cout << "v\n";
    }

    cout << robotok << "\n";
    
}
SubtaskSumTestVerdictTimeMemory
base22/50
1Accepted0/03ms2108 KiB
2Runtime error0/025ms50544 KiB
3Accepted2/22ms2448 KiB
4Accepted2/22ms2788 KiB
5Accepted2/22ms2724 KiB
6Accepted2/24ms3412 KiB
7Accepted2/24ms3540 KiB
8Accepted2/23ms4944 KiB
9Accepted2/23ms4888 KiB
10Accepted2/23ms5064 KiB
11Accepted2/28ms5884 KiB
12Accepted2/227ms9464 KiB
13Accepted2/210ms18168 KiB
14Runtime error0/229ms52208 KiB
15Runtime error0/229ms52208 KiB
16Runtime error0/229ms61952 KiB
17Runtime error0/424ms52672 KiB
18Runtime error0/629ms52552 KiB
19Runtime error0/629ms52552 KiB
20Runtime error0/629ms52452 KiB