Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- ifstream fin("dreptunghi.in");
- ofstream fout("dreptunghi.out");
- const int nmax = 1000;
- int n, m, a[nmax + 5], b[nmax + 5], st[nmax + 5], dr[nmax + 5],aux[nmax + 5][nmax + 5], ans;
- bool matrix[nmax + 5][nmax + 5];
- stack < int > S;
- void read()
- {
- fin >> n >> m;
- for(int i = 1; i <= n; ++i)
- for(int j = 1; j <= m; ++j)
- fin >> matrix[i][j];
- }
- int Arie(int *v)
- {
- while(!S.empty())
- S.pop();
- S.push(0);
- for(int i = 1; i <= m; ++i)
- {
- while(!S.empty() && v[i] <= v[S.top()])
- S.pop();
- if(S.empty())
- st[i] = 1;
- else
- st[i] = S.top() + 1;
- S.push(i);
- }
- while(!S.empty())
- S.pop();
- S.push(m + 1);
- for(int i = m; i >= 1; i--)
- {
- while(!S.empty() && v[i] <= v[S.top()])
- S.pop();
- if(S.empty())
- dr[i] = m;
- else
- dr[i] = S.top() - 1;
- S.push(i);
- }
- int maxx = 0;
- for(int i = 1; i < n; ++i)
- maxx = max(maxx, (dr[i] - st[i] + 1)*v[i]);
- return maxx;
- }
- void solve()
- {
- for(int i = 1; i <= n; ++i)
- {
- for(int j = 1; j <= m; ++j)
- if(matrix[i][j] == 1)
- aux[i][j] = aux[i - 1][j] + 1;
- a[i] = max(a[i - 1], Arie(aux[i]));
- }
- for(int i = 1; i <= n; ++i)
- for(int j = 1; j <= m; ++j)
- aux[i][j] = 0;
- for(int i = 1; i <= n; ++i)
- ans = max(ans, a[i]);
- fout << ans;
- }
- int main()
- {
- read();
- solve();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement