23242023-01-10 14:00:26bzsofiaRobotokcpp11Runtime error 10/50456ms62600 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()
{
    ios::sync_with_stdio(0);
    cin.tie(0);

    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>0)
    {
        ++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
base10/50
1Accepted0/03ms1828 KiB
2Runtime error0/021ms55252 KiB
3Accepted2/24ms2644 KiB
4Accepted2/24ms2844 KiB
5Wrong answer0/24ms3012 KiB
6Wrong answer0/24ms2964 KiB
7Wrong answer0/24ms3220 KiB
8Accepted2/221ms34388 KiB
9Accepted2/218ms34512 KiB
10Accepted2/218ms34588 KiB
11Wrong answer0/213ms4568 KiB
12Time limit exceeded0/2456ms18584 KiB
13Runtime error0/228ms62600 KiB
14Runtime error0/223ms56976 KiB
15Runtime error0/221ms57104 KiB
16Runtime error0/223ms60444 KiB
17Runtime error0/426ms57364 KiB
18Runtime error0/623ms57432 KiB
19Runtime error0/626ms57628 KiB
20Runtime error0/627ms57824 KiB