# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
404582 |
2021-05-14T16:52:26 Z |
rama_pang |
Bomb (IZhO17_bomb) |
C++17 |
|
479 ms |
80068 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, 1e9);
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]) {
int jj = j;
while (jj + 1 <= M && A[i][jj]) jj += 1;
int len = jj - j + 1;
int minUp = 1e9;
int minDn = 1e9;
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[0] = min(ans[0], up[i][j] + dn[i][j] - 1);
ans[len + 1] = 0;
j = jj;
}
}
for (int i = 1; i <= N; i++) {
for (int j = 1; 2 * 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 |
14 ms |
30380 KB |
Output is correct |
4 |
Correct |
15 ms |
30328 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 |
572 KB |
Output is correct |
9 |
Correct |
1 ms |
580 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 |
456 KB |
Output is correct |
13 |
Correct |
1 ms |
460 KB |
Output is correct |
14 |
Correct |
1 ms |
452 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 |
1 ms |
1220 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 |
2 ms |
1356 KB |
Output is correct |
25 |
Correct |
2 ms |
1664 KB |
Output is correct |
26 |
Incorrect |
2 ms |
1612 KB |
Output isn't correct |
27 |
Incorrect |
6 ms |
4804 KB |
Output isn't correct |
28 |
Correct |
6 ms |
5196 KB |
Output is correct |
29 |
Correct |
8 ms |
6604 KB |
Output is correct |
30 |
Correct |
10 ms |
7884 KB |
Output is correct |
31 |
Correct |
9 ms |
6220 KB |
Output is correct |
32 |
Correct |
9 ms |
7116 KB |
Output is correct |
33 |
Correct |
11 ms |
8232 KB |
Output is correct |
34 |
Correct |
6 ms |
5580 KB |
Output is correct |
35 |
Correct |
11 ms |
8272 KB |
Output is correct |
36 |
Incorrect |
12 ms |
8272 KB |
Output isn't correct |
37 |
Correct |
1 ms |
460 KB |
Output is correct |
38 |
Correct |
458 ms |
79084 KB |
Output is correct |
39 |
Correct |
2 ms |
460 KB |
Output is correct |
40 |
Correct |
68 ms |
20616 KB |
Output is correct |
41 |
Correct |
1 ms |
460 KB |
Output is correct |
42 |
Correct |
2 ms |
1612 KB |
Output is correct |
43 |
Correct |
396 ms |
79948 KB |
Output is correct |
44 |
Correct |
11 ms |
8268 KB |
Output is correct |
45 |
Correct |
388 ms |
79896 KB |
Output is correct |
46 |
Correct |
417 ms |
79992 KB |
Output is correct |
47 |
Correct |
396 ms |
79220 KB |
Output is correct |
48 |
Correct |
381 ms |
79892 KB |
Output is correct |
49 |
Incorrect |
463 ms |
79864 KB |
Output isn't correct |
50 |
Correct |
389 ms |
79940 KB |
Output is correct |
51 |
Correct |
376 ms |
79964 KB |
Output is correct |
52 |
Correct |
376 ms |
79876 KB |
Output is correct |
53 |
Correct |
377 ms |
80048 KB |
Output is correct |
54 |
Correct |
338 ms |
79964 KB |
Output is correct |
55 |
Correct |
326 ms |
78860 KB |
Output is correct |
56 |
Correct |
461 ms |
78696 KB |
Output is correct |
57 |
Correct |
325 ms |
78652 KB |
Output is correct |
58 |
Correct |
352 ms |
78748 KB |
Output is correct |
59 |
Correct |
357 ms |
78636 KB |
Output is correct |
60 |
Incorrect |
372 ms |
78632 KB |
Output isn't correct |
61 |
Incorrect |
463 ms |
78740 KB |
Output isn't correct |
62 |
Incorrect |
479 ms |
79976 KB |
Output isn't correct |
63 |
Incorrect |
452 ms |
79940 KB |
Output isn't correct |
64 |
Incorrect |
344 ms |
80004 KB |
Output isn't correct |
65 |
Correct |
365 ms |
79940 KB |
Output is correct |
66 |
Correct |
374 ms |
80028 KB |
Output is correct |
67 |
Correct |
382 ms |
80056 KB |
Output is correct |
68 |
Correct |
393 ms |
79644 KB |
Output is correct |
69 |
Correct |
326 ms |
78544 KB |
Output is correct |
70 |
Correct |
183 ms |
62976 KB |
Output is correct |
71 |
Correct |
303 ms |
78476 KB |
Output is correct |
72 |
Correct |
317 ms |
78624 KB |
Output is correct |
73 |
Correct |
343 ms |
78584 KB |
Output is correct |
74 |
Correct |
320 ms |
79696 KB |
Output is correct |
75 |
Correct |
315 ms |
79700 KB |
Output is correct |
76 |
Correct |
328 ms |
79964 KB |
Output is correct |
77 |
Correct |
323 ms |
79844 KB |
Output is correct |
78 |
Correct |
324 ms |
79960 KB |
Output is correct |
79 |
Correct |
274 ms |
79868 KB |
Output is correct |
80 |
Correct |
268 ms |
79864 KB |
Output is correct |
81 |
Correct |
274 ms |
78380 KB |
Output is correct |
82 |
Correct |
330 ms |
78460 KB |
Output is correct |
83 |
Correct |
329 ms |
78500 KB |
Output is correct |
84 |
Correct |
271 ms |
78436 KB |
Output is correct |
85 |
Correct |
345 ms |
78504 KB |
Output is correct |
86 |
Correct |
438 ms |
78404 KB |
Output is correct |
87 |
Correct |
318 ms |
78412 KB |
Output is correct |
88 |
Correct |
324 ms |
78448 KB |
Output is correct |
89 |
Correct |
362 ms |
79940 KB |
Output is correct |
90 |
Correct |
212 ms |
63064 KB |
Output is correct |
91 |
Correct |
341 ms |
79964 KB |
Output is correct |
92 |
Correct |
357 ms |
79852 KB |
Output is correct |
93 |
Correct |
436 ms |
80068 KB |
Output is correct |
94 |
Correct |
359 ms |
79892 KB |
Output is correct |
95 |
Correct |
332 ms |
79984 KB |
Output is correct |
96 |
Correct |
336 ms |
78328 KB |
Output is correct |
97 |
Correct |
440 ms |
78272 KB |
Output is correct |
98 |
Correct |
354 ms |
78264 KB |
Output is correct |
99 |
Correct |
354 ms |
78384 KB |
Output is correct |
100 |
Correct |
431 ms |
78404 KB |
Output is correct |