0

I'm solving some simple problem, but I have a problem, I can only input variables N, M and P, I can't input variables tempX and tempY which are in loop, here is the code:

#include <iostream>
#include <vector>
#include <minmax.h>

using namespace std;

typedef unsigned long long ull;

int main() {
ull n, m, p;
cin >> n >> m >> p;

vector<vector<unsigned short> > field;
field.resize(n);

for (ull i = 0; i < m; i++)
    for (ull j = 0; j < m; j++)
        field[i].push_back(1);



for (ull i = 0; i < p; i++) {
    ull tempX, tempY;
    cin >> tempX >> tempY;
    field[tempX][tempY] = 0;
}

for (ull i = 1; i < n; i++)
    for (ull j = 1; j < m; j++)
        if (field[i - 1][j - 1] != 0 && field[i][j] != 0)
            field[i][j] = min(field[i - 1][j], field[i][j - 1]) + 1;

ull maxLength = 0;
for (ull i = 0; i < n; i++)
    for (ull j = 0; j < m; j++)
        maxLength = max(maxLength, field[i][j]);

cout << maxLength << endl;

return 0;
}

Btw. I had problems with printing simple text with cout, there was no problem in code but something is preventing printing simple text like "Hello world", is that connected in any way with this problem?

1 Answers1

0
vector<vector<unsigned short> > field;
field.resize(n);

for (ull i = 0; i < m; i++)
    for (ull j = 0; j < m; j++)
        field[i].push_back(1);

there's a mistake already there. m instead of n

for (ull i = 0; i < n; i++)

You should properly name your variables. n is not a good name. numberOfRows or rowCount or matrixDimension1 could be better.

By the way, use stl.

for (ull i = 0; i < n; i++)
    for (ull j = 0; j < m; j++)
        field[i].push_back(1);

could be

for (ull i = 0; i < field.size(); i++)
    field[i].resize(m, 1);

And it could be more simple. Just look at examples online.

JHBonarius
  • 10,824
  • 3
  • 22
  • 41