# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
404588 |
2021-05-14T17:11:17 Z |
rama_pang |
Bomb (IZhO17_bomb) |
C++17 |
|
447 ms |
74044 KB |
#include <bits/stdc++.h>
using namespace std;
int N, M;
int A[2505][2505];
int up[2505][2505];
int dn[2505][2505];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> N >> M;
for (int i = 1; i <= N; i++) {
for (int j = 1; j <= M; j++) {
char c;
cin >> c;
A[i][j] = c - '0';
}
}
// Solution:
//
// The upper bound on height and width is the minimum length
// vertical and horizontal strip. Now, for a fixed width Y,
// we want to determine the maximum height X. Note that,
// if we have width Y, then for every maximal horizontal
// strip, height is bounded by the minimum (top - bottom)
// of the prefix and suffix of size Y.
//
// We only need to consider the prefix and suffix. Why?
// For, after a prefix of size Y, let's move it to the right.
// If the (top - bottom) decreased, that means that there is
// a vertical strip which is shifted downwards, which means
// it will occcupy a maximal horizontal strip -> we will compute
// it later.
//
// Time complexity: O(N M).
for (int j = 1; j <= M; j++) {
for (int i = 1; i <= N; i++) {
if (A[i][j]) {
up[i][j] = 1 + up[i - 1][j];
}
}
for (int i = N; i >= 1; i--) {
if (A[i][j]) {
dn[i][j] = 1 + dn[i + 1][j];
}
}
}
vector<int> ans(M + 2, N);
for (int rep = 0; rep < 2; rep++) { // for prefix, then suffix
for (int i = 1; i <= N; i++) {
for (int j = 1; j <= M; j++) if (A[i][j] && !A[i][j - 1]) {
int jj = j;
while (jj + 1 <= M && A[i][jj + 1]) jj += 1;
int len = jj - j + 1;
int minUp = N;
int minDn = N;
for (int k = 1; k <= len; k++) {
minUp = min(minUp, up[i][j + k - 1]);
minDn = min(minDn, dn[i][j + k - 1]);
ans[k] = min(ans[k], minUp + minDn - 1);
}
ans[len + 1] = 0;
j = jj;
}
}
for (int i = 1; i <= N; i++) {
for (int j = 1; j + j <= M; j++) {
swap(A[i][j], A[i][M - j + 1]);
swap(up[i][j], up[i][M - j + 1]);
swap(dn[i][j], dn[i][M - j + 1]);
}
}
}
int answer = 0;
for (int i = 1; i <= M; i++) {
ans[i] = min(ans[i], ans[i - 1]);
answer = max(answer, i * ans[i]);
}
cout << answer << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
460 KB |
Output is correct |
3 |
Correct |
13 ms |
30340 KB |
Output is correct |
4 |
Correct |
14 ms |
30316 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
8 |
Correct |
1 ms |
460 KB |
Output is correct |
9 |
Correct |
1 ms |
460 KB |
Output is correct |
10 |
Correct |
1 ms |
460 KB |
Output is correct |
11 |
Correct |
1 ms |
460 KB |
Output is correct |
12 |
Correct |
1 ms |
460 KB |
Output is correct |
13 |
Correct |
1 ms |
460 KB |
Output is correct |
14 |
Correct |
1 ms |
460 KB |
Output is correct |
15 |
Correct |
1 ms |
460 KB |
Output is correct |
16 |
Correct |
1 ms |
460 KB |
Output is correct |
17 |
Correct |
1 ms |
1100 KB |
Output is correct |
18 |
Correct |
2 ms |
1228 KB |
Output is correct |
19 |
Correct |
2 ms |
1484 KB |
Output is correct |
20 |
Correct |
2 ms |
1484 KB |
Output is correct |
21 |
Correct |
1 ms |
972 KB |
Output is correct |
22 |
Correct |
1 ms |
1228 KB |
Output is correct |
23 |
Correct |
2 ms |
1612 KB |
Output is correct |
24 |
Correct |
1 ms |
1356 KB |
Output is correct |
25 |
Correct |
2 ms |
1612 KB |
Output is correct |
26 |
Incorrect |
2 ms |
1612 KB |
Output isn't correct |
27 |
Incorrect |
5 ms |
4748 KB |
Output isn't correct |
28 |
Correct |
6 ms |
5068 KB |
Output is correct |
29 |
Correct |
7 ms |
6476 KB |
Output is correct |
30 |
Correct |
11 ms |
7628 KB |
Output is correct |
31 |
Correct |
8 ms |
6092 KB |
Output is correct |
32 |
Correct |
8 ms |
6988 KB |
Output is correct |
33 |
Correct |
10 ms |
8012 KB |
Output is correct |
34 |
Correct |
5 ms |
5580 KB |
Output is correct |
35 |
Correct |
10 ms |
8136 KB |
Output is correct |
36 |
Incorrect |
11 ms |
8140 KB |
Output isn't correct |
37 |
Correct |
1 ms |
460 KB |
Output is correct |
38 |
Correct |
419 ms |
73816 KB |
Output is correct |
39 |
Correct |
1 ms |
460 KB |
Output is correct |
40 |
Correct |
54 ms |
19980 KB |
Output is correct |
41 |
Correct |
1 ms |
460 KB |
Output is correct |
42 |
Correct |
2 ms |
1612 KB |
Output is correct |
43 |
Correct |
361 ms |
73824 KB |
Output is correct |
44 |
Correct |
10 ms |
8012 KB |
Output is correct |
45 |
Correct |
348 ms |
73808 KB |
Output is correct |
46 |
Correct |
346 ms |
73828 KB |
Output is correct |
47 |
Correct |
363 ms |
73820 KB |
Output is correct |
48 |
Correct |
336 ms |
73800 KB |
Output is correct |
49 |
Incorrect |
424 ms |
73952 KB |
Output isn't correct |
50 |
Correct |
341 ms |
73800 KB |
Output is correct |
51 |
Correct |
336 ms |
73748 KB |
Output is correct |
52 |
Correct |
339 ms |
73812 KB |
Output is correct |
53 |
Correct |
339 ms |
73752 KB |
Output is correct |
54 |
Correct |
304 ms |
73856 KB |
Output is correct |
55 |
Correct |
291 ms |
73784 KB |
Output is correct |
56 |
Correct |
435 ms |
73924 KB |
Output is correct |
57 |
Correct |
316 ms |
73812 KB |
Output is correct |
58 |
Correct |
296 ms |
73840 KB |
Output is correct |
59 |
Correct |
296 ms |
73780 KB |
Output is correct |
60 |
Incorrect |
336 ms |
73752 KB |
Output isn't correct |
61 |
Incorrect |
447 ms |
74044 KB |
Output isn't correct |
62 |
Incorrect |
427 ms |
73756 KB |
Output isn't correct |
63 |
Incorrect |
429 ms |
73796 KB |
Output isn't correct |
64 |
Incorrect |
297 ms |
73852 KB |
Output isn't correct |
65 |
Correct |
354 ms |
73844 KB |
Output is correct |
66 |
Correct |
340 ms |
73808 KB |
Output is correct |
67 |
Correct |
355 ms |
73796 KB |
Output is correct |
68 |
Correct |
380 ms |
73812 KB |
Output is correct |
69 |
Correct |
294 ms |
73736 KB |
Output is correct |
70 |
Correct |
173 ms |
59128 KB |
Output is correct |
71 |
Correct |
266 ms |
73784 KB |
Output is correct |
72 |
Correct |
307 ms |
73844 KB |
Output is correct |
73 |
Correct |
292 ms |
73828 KB |
Output is correct |
74 |
Correct |
303 ms |
73796 KB |
Output is correct |
75 |
Correct |
313 ms |
73848 KB |
Output is correct |
76 |
Correct |
306 ms |
73852 KB |
Output is correct |
77 |
Correct |
302 ms |
73828 KB |
Output is correct |
78 |
Correct |
345 ms |
73776 KB |
Output is correct |
79 |
Correct |
250 ms |
73812 KB |
Output is correct |
80 |
Correct |
245 ms |
73804 KB |
Output is correct |
81 |
Correct |
253 ms |
73832 KB |
Output is correct |
82 |
Correct |
324 ms |
73860 KB |
Output is correct |
83 |
Correct |
297 ms |
73824 KB |
Output is correct |
84 |
Correct |
247 ms |
73896 KB |
Output is correct |
85 |
Correct |
297 ms |
73760 KB |
Output is correct |
86 |
Correct |
417 ms |
73856 KB |
Output is correct |
87 |
Correct |
300 ms |
73784 KB |
Output is correct |
88 |
Correct |
297 ms |
73764 KB |
Output is correct |
89 |
Correct |
332 ms |
73848 KB |
Output is correct |
90 |
Correct |
200 ms |
59152 KB |
Output is correct |
91 |
Correct |
318 ms |
73788 KB |
Output is correct |
92 |
Correct |
329 ms |
73756 KB |
Output is correct |
93 |
Correct |
400 ms |
73900 KB |
Output is correct |
94 |
Correct |
335 ms |
73928 KB |
Output is correct |
95 |
Correct |
309 ms |
73844 KB |
Output is correct |
96 |
Correct |
309 ms |
73768 KB |
Output is correct |
97 |
Correct |
406 ms |
73852 KB |
Output is correct |
98 |
Correct |
307 ms |
73776 KB |
Output is correct |
99 |
Correct |
321 ms |
73736 KB |
Output is correct |
100 |
Correct |
415 ms |
73796 KB |
Output is correct |