-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhinh_chu_nhat_0_1.cpp
More file actions
62 lines (62 loc) · 1.43 KB
/
hinh_chu_nhat_0_1.cpp
File metadata and controls
62 lines (62 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <map>
#include <queue>
#include <stack>
#include <string>
using namespace std;
long long mod = 1e9 + 7;
void slove()
{
int n, m, s = 1;
cin >> n >> m;
vector<vector<int>> a(n, vector<int>(m));
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
cin >> a[i][j];
for (int i = 0; i < m; i++)
for (int j = 1; j < n; j++)
if (a[j][i] == 1)
a[j][i] = a[j - 1][i] + 1;
for (int i = 0; i < n; i++)
{
stack<int> b, c;
int l[m], r[m];
for (int j = 0; j < m; j++)
{
while (!b.empty() && a[i][j] <= a[i][b.top()])
b.pop();
if (b.empty())
l[j] = 0;
else
l[j] = b.top() + 1;
b.push(j);
}
for (int j = m - 1; j >= 0; j--)
{
while (!c.empty() && a[i][j] <= a[i][c.top()])
c.pop();
if (c.empty())
r[j] = m - 1;
else
r[j] = c.top() - 1;
c.push(j);
}
for (int j = 0; j < m; j++)
s = max(s, (r[j] - l[j] + 1) * a[i][j]);
}
cout << s << endl;
}
int main()
{
int t = 1;
cin >> t;
while (t--)
{
slove();
}
return 0;
}