Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdio>
- #include <stack>
- #include <utility>
- #define max(a, b) ((a) > (b) ? (a) : (b))
- #define abs(a) ((a) > 0 ? (a) : -(a))
- using namespace std;
- int tab[2002][2002];
- int gl[2002][2002];
- stack< pair<int, int> > stos;
- int main()
- {
- int n, i, j, w = 0;
- scanf("%d", &n);
- for (i = 1; i <= n; i++)
- {
- for (j = 1; j <= n; j++)
- {
- scanf("%d", &tab[i][j]);
- }
- for (j = 1; j <= n; j++)
- {
- if (tab[i][j] == 0)
- gl[i][j] = gl[i-1][j]+1;
- }
- }
- /*printf("\n");
- for (i = 1; i <= n; i++)
- {
- for (j = 1; j <= n; j++)
- printf("%d ", gl[i][j]);
- printf("\n");
- }*/
- for (i = 1; i <= n+1; i++)
- {
- for (j = 1; j <= n+1; j++)
- {
- pair<int, int> last, p;
- bool bylo = false;
- if (!stos.empty())
- p = stos.top();
- while (!stos.empty() && p.second > gl[i][j])
- {
- //printf("TU (%d, %d):\n", i, j);
- w = max(w, ((j-p.first)*p.second));
- /*if (w == ((j-p.first)*p.second))
- printf(" NOWY WYNIK - w: %d, i: %d, j: %d, j-p.first: %d\n", w, i, j, j-p.first);*/
- last = stos.top();
- stos.pop();
- bylo = true;
- if (!stos.empty())
- p = stos.top();
- }
- if (((stos.empty() && gl[i][j] > 0) || p.second < gl[i][j]))
- {
- if (bylo)
- stos.push(make_pair(last.first, gl[i][j]));//, printf("PUSH 1: (%d, %d)\n", last.first, gl[i][j]);
- else
- stos.push(make_pair(j, gl[i][j]));//, printf("PUSH 2: (%d, %d)\n", j, gl[i][j]);
- }
- }
- }
- printf("%d\n", w);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement