-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path836.cpp
61 lines (52 loc) · 1.29 KB
/
836.cpp
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
#include <bits/stdc++.h>
using namespace std;
int main()
{
int T, line_idx;
int N, M, i, j, k, l;
int sum_mat[25][25];
int curr_sum, curr_area;
int max_area = 0;
bool first = true;
string mat[25];
string line;
getline(cin, line);
T = stoi(line, nullptr);
getline(cin, line); // read empty line
while (T--)
{
getline(cin, line);
line_idx = 0, max_area = 0;
while (line[0] == '0' or line[0] == '1')
{
mat[line_idx++] = line;
getline(cin, line);
}
if (!first)
cout << "\n";
first = false;
N = line_idx, M = (int)mat[0].size();
for (i = 0; i < N; i++)
for (j = 0; j < M; j++)
{
sum_mat[i][j] = int(mat[i][j] - '0');
if (i > 0) sum_mat[i][j] += sum_mat[i - 1][j];
if (j > 0) sum_mat[i][j] += sum_mat[i][j - 1];
if (i > 0 and j > 0) sum_mat[i][j] -= sum_mat[i - 1][j - 1];
}
for (i = 0; i < N; i++)
for (j = 0; j < M; j++)
for (k = i; k < N; k++)
for (l = j; l < M; l++)
{
curr_sum = sum_mat[k][l];
if (i > 0) curr_sum -= sum_mat[i - 1][l];
if (j > 0) curr_sum -= sum_mat[k][j - 1];
if (i > 0 and j > 0) curr_sum += sum_mat[i - 1][j - 1];
curr_area = (k - i + 1) * (l - j + 1);
if (curr_area == curr_sum and curr_area > max_area)
max_area = curr_area;
}
cout << max_area << "\n";
}
}