#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define vt vector
#define f first
#define s second
#define all(x) (x).begin(), (x).end()
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, b) FOR(i, 0, b)
#define ROF(i, a, b) for (int i = (b) - 1; i >= (a); i--)
#define pb push_back
#define endl '\n'
#ifndef LOCAL
#define cerr if (0) std::cerr
#endif
/*
N^3: find max width for each given height
*/
int rs, cs;
vt<vt<bool>> grid;
vt<vt<int>> sfx;
int sum(int r1, int c1, int r2, int c2) {
r2 = min(r2, rs - 1);
c2 = min(c2, cs - 1);
return sfx[r1][c1] - sfx[r1][c2 + 1] - sfx[r2 + 1][c1] + sfx[r2 + 1][c2 + 1];
}
main() {
cin.tie(0)->sync_with_stdio();
cin >> rs >> cs;
rs += 2, cs += 2;
grid.resize(rs, vt<bool>(cs));
sfx.resize(rs + 1, vt<int>(cs + 1));
FOR (r, 1, rs - 1) {
FOR (c, 1, cs - 1) {
char ch; cin >> ch;
grid[r][c] = sfx[r][c] = ch - '0';
}
}
ROF (r, 0, rs) ROF (c, 0, cs) sfx[r][c] += sfx[r][c + 1];
ROF (r, 0, rs) ROF (c, 0, cs) sfx[r][c] += sfx[r + 1][c];
int mxw = cs, mxh = rs;
F0R (r, rs) {
int streak = 0;
F0R (c, cs) {
if (grid[r][c]) streak++;
else if (streak) mxw = min(mxw, streak), streak = 0;
}
}
F0R (c, cs) {
int streak = 0;
F0R (r, rs) {
if (grid[r][c]) streak++;
else if (streak) mxh = min(mxh, streak), streak = 0;
}
}
cerr << mxw << " " << mxh << endl;
int best = 0;
FOR (h, 1, mxh + 1) {
FOR (w, 1, mxw + 1) {
vt<vt<int>> pfx(rs, vt<int>(cs));
auto is_covered = [&] (int r, int c) {
return (pfx[r][c] - (r - h >= 0 ? pfx[r - h][c] : 0) - (c - w >= 0 ? pfx[r][c - w] : 0) + (r - h >= 0 && c - w >= 0 ? pfx[r - h][c - w] : 0)) > 0;
};
auto add = [&] (int r, int c) {
pfx[r][c] += (r ? pfx[r - 1][c] : 0) + (c ? pfx[r][c - 1] : 0) - (r && c ? pfx[r - 1][c - 1] : 0);
};
cerr << w << " " << h << endl;
bool good = true;
F0R (r, rs - 1) {
F0R (c, cs - 1) {
if (sum(r, c, r + h - 1, c + w - 1) == w * h) {
pfx[r][c]++;
}
add(r, c);
if (grid[r][c] == 1) {
cerr << is_covered(r, c) << endl;
good &= is_covered(r, c);
}
}
}
if (good) best = max(best, w * h);
}
}
cout << best << endl;
}
Compilation message
bomb.cpp:36:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
36 | main() {
| ^~~~
bomb.cpp: In function 'int main()':
bomb.cpp:46:36: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
46 | grid[r][c] = sfx[r][c] = ch - '0';
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
436 KB |
Output is correct |
3 |
Correct |
4 ms |
860 KB |
Output is correct |
4 |
Correct |
5 ms |
860 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
13 ms |
516 KB |
Output is correct |
20 |
Correct |
11 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
2 ms |
348 KB |
Output is correct |
23 |
Correct |
33 ms |
348 KB |
Output is correct |
24 |
Correct |
14 ms |
348 KB |
Output is correct |
25 |
Correct |
68 ms |
516 KB |
Output is correct |
26 |
Correct |
7 ms |
348 KB |
Output is correct |
27 |
Correct |
3 ms |
1180 KB |
Output is correct |
28 |
Correct |
30 ms |
1480 KB |
Output is correct |
29 |
Execution timed out |
1055 ms |
1596 KB |
Time limit exceeded |
30 |
Execution timed out |
1020 ms |
2240 KB |
Time limit exceeded |
31 |
Execution timed out |
1087 ms |
2072 KB |
Time limit exceeded |
32 |
Execution timed out |
1010 ms |
2112 KB |
Time limit exceeded |
33 |
Execution timed out |
1028 ms |
2300 KB |
Time limit exceeded |
34 |
Correct |
36 ms |
1468 KB |
Output is correct |
35 |
Execution timed out |
1052 ms |
2316 KB |
Time limit exceeded |
36 |
Execution timed out |
1072 ms |
2300 KB |
Time limit exceeded |
37 |
Correct |
0 ms |
348 KB |
Output is correct |
38 |
Execution timed out |
1098 ms |
56700 KB |
Time limit exceeded |
39 |
Correct |
1 ms |
344 KB |
Output is correct |
40 |
Execution timed out |
1076 ms |
7652 KB |
Time limit exceeded |
41 |
Correct |
1 ms |
344 KB |
Output is correct |
42 |
Correct |
109 ms |
512 KB |
Output is correct |
43 |
Execution timed out |
1073 ms |
56604 KB |
Time limit exceeded |
44 |
Execution timed out |
1043 ms |
2320 KB |
Time limit exceeded |
45 |
Execution timed out |
1053 ms |
56596 KB |
Time limit exceeded |
46 |
Execution timed out |
1024 ms |
56704 KB |
Time limit exceeded |
47 |
Execution timed out |
1038 ms |
56700 KB |
Time limit exceeded |
48 |
Execution timed out |
1027 ms |
56744 KB |
Time limit exceeded |
49 |
Execution timed out |
1036 ms |
56988 KB |
Time limit exceeded |
50 |
Execution timed out |
1044 ms |
56780 KB |
Time limit exceeded |
51 |
Execution timed out |
1053 ms |
56696 KB |
Time limit exceeded |
52 |
Execution timed out |
1029 ms |
56756 KB |
Time limit exceeded |
53 |
Execution timed out |
1022 ms |
56740 KB |
Time limit exceeded |
54 |
Execution timed out |
1042 ms |
56736 KB |
Time limit exceeded |
55 |
Execution timed out |
1029 ms |
56748 KB |
Time limit exceeded |
56 |
Execution timed out |
1056 ms |
56960 KB |
Time limit exceeded |
57 |
Execution timed out |
1058 ms |
56932 KB |
Time limit exceeded |
58 |
Execution timed out |
1060 ms |
56696 KB |
Time limit exceeded |
59 |
Execution timed out |
1044 ms |
56984 KB |
Time limit exceeded |
60 |
Execution timed out |
1041 ms |
56748 KB |
Time limit exceeded |
61 |
Execution timed out |
1031 ms |
56696 KB |
Time limit exceeded |
62 |
Execution timed out |
1025 ms |
56696 KB |
Time limit exceeded |
63 |
Execution timed out |
1014 ms |
56696 KB |
Time limit exceeded |
64 |
Execution timed out |
1041 ms |
56700 KB |
Time limit exceeded |
65 |
Execution timed out |
1061 ms |
56804 KB |
Time limit exceeded |
66 |
Execution timed out |
1076 ms |
56948 KB |
Time limit exceeded |
67 |
Execution timed out |
1027 ms |
56700 KB |
Time limit exceeded |
68 |
Execution timed out |
1012 ms |
56696 KB |
Time limit exceeded |
69 |
Execution timed out |
1060 ms |
56700 KB |
Time limit exceeded |
70 |
Execution timed out |
1076 ms |
36460 KB |
Time limit exceeded |
71 |
Execution timed out |
1067 ms |
56720 KB |
Time limit exceeded |
72 |
Execution timed out |
1063 ms |
56700 KB |
Time limit exceeded |
73 |
Execution timed out |
1068 ms |
56904 KB |
Time limit exceeded |
74 |
Execution timed out |
1037 ms |
56696 KB |
Time limit exceeded |
75 |
Execution timed out |
1020 ms |
56700 KB |
Time limit exceeded |
76 |
Execution timed out |
1043 ms |
56744 KB |
Time limit exceeded |
77 |
Execution timed out |
1077 ms |
56752 KB |
Time limit exceeded |
78 |
Execution timed out |
1057 ms |
56816 KB |
Time limit exceeded |
79 |
Execution timed out |
1030 ms |
56944 KB |
Time limit exceeded |
80 |
Execution timed out |
1069 ms |
56576 KB |
Time limit exceeded |
81 |
Execution timed out |
1067 ms |
56960 KB |
Time limit exceeded |
82 |
Execution timed out |
1055 ms |
56744 KB |
Time limit exceeded |
83 |
Execution timed out |
1057 ms |
56944 KB |
Time limit exceeded |
84 |
Execution timed out |
1018 ms |
56700 KB |
Time limit exceeded |
85 |
Execution timed out |
1046 ms |
56936 KB |
Time limit exceeded |
86 |
Execution timed out |
1041 ms |
56704 KB |
Time limit exceeded |
87 |
Execution timed out |
1022 ms |
56988 KB |
Time limit exceeded |
88 |
Execution timed out |
1043 ms |
56708 KB |
Time limit exceeded |
89 |
Execution timed out |
1071 ms |
56952 KB |
Time limit exceeded |
90 |
Execution timed out |
1056 ms |
36520 KB |
Time limit exceeded |
91 |
Execution timed out |
1054 ms |
56828 KB |
Time limit exceeded |
92 |
Execution timed out |
1051 ms |
56824 KB |
Time limit exceeded |
93 |
Execution timed out |
1060 ms |
56868 KB |
Time limit exceeded |
94 |
Execution timed out |
1052 ms |
56700 KB |
Time limit exceeded |
95 |
Execution timed out |
1028 ms |
56696 KB |
Time limit exceeded |
96 |
Execution timed out |
1057 ms |
56880 KB |
Time limit exceeded |
97 |
Execution timed out |
1066 ms |
56708 KB |
Time limit exceeded |
98 |
Execution timed out |
1044 ms |
56696 KB |
Time limit exceeded |
99 |
Execution timed out |
1070 ms |
56708 KB |
Time limit exceeded |
100 |
Execution timed out |
1060 ms |
56832 KB |
Time limit exceeded |