rotti321

Untitled

Mar 21st, 2017
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.29 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. constexpr int maxn = 1010;
  5.  
  6. int v[maxn][maxn], h[maxn] = {}, st[maxn], dr[maxn], stiva[maxn] = {}, poz = -1,
  7.     n, m;
  8. ifstream f("hambar.in");
  9. ofstream g("hambar.out");
  10.  
  11. void do_st_dr(){
  12.     stiva[poz=0] = -1;
  13.     for(int i = 0; i < n; ++i){
  14.         while(stiva[poz] != -1 && h[stiva[poz]] >= h[i]) --poz;
  15.         st[i] = stiva[poz]+1;
  16.         stiva[++poz] = i; }
  17.     stiva[poz=0] = n;
  18.     for(int i = n-1; i >= 0; --i){
  19.         while(stiva[poz] != n && h[stiva[poz]] >= h[i]) --poz;
  20.         dr[i] = stiva[poz]-1;
  21.         stiva[++poz] = i; } }
  22.  
  23. int main(){
  24.     f >> n >> m;
  25.     for(int i = 0, x, y; i < m; ++i)
  26.         f >> x >> y,
  27.         v[x-1][y-1] = 1;
  28.  
  29.     int rez = 0;
  30.     for(int i = 0; i < n; ++i){
  31.         for(int j = 0; j < n; ++j)
  32.             if(!v[i][j]) ++h[j];
  33.             else h[j] = 0;
  34.         do_st_dr();
  35. /**        for(int j = 0; j < n; ++j) cout << h[j] << ' ';
  36.         cout << endl;
  37.  
  38.         for(int j = 0; j < n; ++j) cout << st[j] << ' ';
  39.         cout << endl;
  40.  
  41.         for(int j = 0; j < n; ++j) cout << dr[j] << ' ';
  42.         cout << endl;
  43.         cout << endl;
  44.         **/
  45.         for(int j = 0; j < n; ++j)
  46.             rez = max(rez, h[j] * (dr[j] - st[j] + 1)); }
  47.     g << rez << endl;
  48.     return 0; }
Add Comment
Please, Sign In to add comment