23232023-01-10 13:55:32bzsofiaRobotokcpp11Futási hiba 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
RészfeladatÖsszpontTesztVerdiktIdőMemória
base4/50
1Elfogadva0/03ms1808 KiB
2Futási hiba0/027ms55624 KiB
3Elfogadva2/24ms2496 KiB
4Elfogadva2/24ms2572 KiB
5Hibás válasz0/24ms2700 KiB
6Időlimit túllépés0/2500ms1956 KiB
7Időlimit túllépés0/2458ms2224 KiB
8Időlimit túllépés0/2446ms17924 KiB
9Időlimit túllépés0/2451ms18088 KiB
10Időlimit túllépés0/2467ms18096 KiB
11Időlimit túllépés0/2469ms2980 KiB
12Időlimit túllépés0/2453ms18028 KiB
13Futási hiba0/223ms62116 KiB
14Futási hiba0/226ms56928 KiB
15Futási hiba0/227ms56868 KiB
16Futási hiba0/228ms60320 KiB
17Futási hiba0/427ms57144 KiB
18Futási hiba0/627ms56984 KiB
19Futási hiba0/626ms56980 KiB
20Futási hiba0/626ms56984 KiB