23232023-01-10 13:55:32bzsofiaRobotokcpp11Runtime error 4/50500ms62116 KiB
// Robotok.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include <fstream>
#include <vector>

using namespace std;

struct adat
{
    int robi, sum;
    pair <int, int> honnan;
};

int i, n, m, db, robot, j, a, b;

int main()
{
    cin >> n >> m >> db;
    vector <vector<adat>> x(n+1, vector <adat> (m+1));
    
    for (i = 1; i <= db; ++i)
    {
        cin >> a >> b;
        x[a][b].robi = 1;
    }
    
    while (db)
    {
        ++robot;

        for (i = 1; i <= n; ++i)
        {
            for (j = 1; j <= m; ++j)
            {
                if (i == 1)
                {
                    x[i][j].sum = x[i][j - 1].sum + x[i][j].robi;
                    x[i][j].honnan = { i, j - 1 };
                }
                else if (j == 1)
                {
                    x[i][j].sum = x[i - 1][j].sum + x[i][j].robi;
                    x[i][j].honnan = { i - 1, j };
                }
                else
                {
                    if (x[i][j - 1].sum > x[i - 1][j].sum)
                    {
                        x[i][j].sum = x[i][j - 1].sum + x[i][j].robi;
                        x[i][j].honnan = { i, j - 1 };
                    }
                    else
                    {
                        x[i][j].sum = x[i - 1][j].sum + x[i][j].robi;
                        x[i][j].honnan = { i - 1, j };
                    }
                }
            }
        }

        i = n;
        j = m;
        db -= x[n][m].sum;
        while (x[i][j].honnan.first && x[i][j].honnan.second)
        {
            x[i][j].robi = 0;
            i = x[i][j].honnan.first;
            j = x[i][j].honnan.second;
        }
    }

    cout << robot;
}

// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
// Debug program: F5 or Debug > Start Debugging menu

// Tips for Getting Started: 
//   1. Use the Solution Explorer window to add/manage files
//   2. Use the Team Explorer window to connect to source control
//   3. Use the Output window to see build output and other messages
//   4. Use the Error List window to view errors
//   5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
//   6. In the future, to open this project again, go to File > Open > Project and select the .sln file
SubtaskSumTestVerdictTimeMemory
base4/50
1Accepted0/03ms1808 KiB
2Runtime error0/027ms55624 KiB
3Accepted2/24ms2496 KiB
4Accepted2/24ms2572 KiB
5Wrong answer0/24ms2700 KiB
6Time limit exceeded0/2500ms1956 KiB
7Time limit exceeded0/2458ms2224 KiB
8Time limit exceeded0/2446ms17924 KiB
9Time limit exceeded0/2451ms18088 KiB
10Time limit exceeded0/2467ms18096 KiB
11Time limit exceeded0/2469ms2980 KiB
12Time limit exceeded0/2453ms18028 KiB
13Runtime error0/223ms62116 KiB
14Runtime error0/226ms56928 KiB
15Runtime error0/227ms56868 KiB
16Runtime error0/228ms60320 KiB
17Runtime error0/427ms57144 KiB
18Runtime error0/627ms56984 KiB
19Runtime error0/626ms56980 KiB
20Runtime error0/626ms56984 KiB