Advertisement
Guest User

Działki

a guest
Jan 17th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.86 KB | None | 0 0
  1. #include <cstdio>
  2. #include <stack>
  3. #include <utility>
  4.  
  5. #define max(a, b) ((a) > (b) ? (a) : (b))
  6. #define abs(a) ((a) > 0 ? (a) : -(a))
  7.  
  8. using namespace std;
  9.  
  10. int tab[2002][2002];
  11. int gl[2002][2002];
  12. stack< pair<int, int> > stos;
  13.  
  14. int main()
  15. {
  16.     int n, i, j, w = 0;
  17.     scanf("%d", &n);
  18.     for (i = 1; i <= n; i++)
  19.     {
  20.         for (j = 1; j <= n; j++)
  21.         {
  22.             scanf("%d", &tab[i][j]);
  23.         }
  24.         for (j = 1; j <= n; j++)
  25.         {
  26.             if (tab[i][j] == 0)
  27.                 gl[i][j] = gl[i-1][j]+1;
  28.         }
  29.     }
  30.     /*printf("\n");
  31.     for (i = 1; i <= n; i++)
  32.     {
  33.         for (j = 1; j <= n; j++)
  34.             printf("%d ", gl[i][j]);
  35.         printf("\n");
  36.     }*/
  37.     for (i = 1; i <= n+1; i++)
  38.     {
  39.         for (j = 1; j <= n+1; j++)
  40.         {
  41.             pair<int, int> last, p;
  42.             bool bylo = false;
  43.             if (!stos.empty())
  44.                 p = stos.top();
  45.             while (!stos.empty() && p.second > gl[i][j])
  46.             {
  47.                 //printf("TU (%d, %d):\n", i, j);
  48.                 w = max(w, ((j-p.first)*p.second));
  49.                 /*if (w == ((j-p.first)*p.second))
  50.                     printf(" NOWY WYNIK - w: %d, i: %d, j: %d, j-p.first: %d\n", w, i, j, j-p.first);*/
  51.                 last = stos.top();
  52.                 stos.pop();
  53.                 bylo = true;
  54.                 if (!stos.empty())
  55.                     p = stos.top();
  56.             }
  57.             if (((stos.empty() && gl[i][j] > 0) || p.second < gl[i][j]))
  58.             {
  59.                 if (bylo)
  60.                     stos.push(make_pair(last.first, gl[i][j]));//, printf("PUSH 1: (%d, %d)\n", last.first, gl[i][j]);
  61.                 else
  62.                     stos.push(make_pair(j, gl[i][j]));//, printf("PUSH 2: (%d, %d)\n", j, gl[i][j]);
  63.             }
  64.         }
  65.     }
  66.     printf("%d\n", w);
  67.     return 0;
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement