# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
423298 |
2021-06-10T23:02:48 Z |
antimirage |
Bomb (IZhO17_bomb) |
C++14 |
|
781 ms |
80540 KB |
/*
* let's for fixed width X find the maximum valid height Y, denote it by ans[X].
* upper bound of Y for every X is ans[1].
*
*/
#include <iostream>
#include <vector>
#include <algorithm>
#include <assert.h>
using namespace std;
int main() {
int n, m, res = 0;
cin >> n >> m;
vector <vector <int>> a(n + 5, vector<int>(m + 5, 0));
for (int i = 1; i <= n; i++) {
scanf("\n");
for (int j = 1; j <= m; j++) {
char ch;
scanf("%c", &ch);
a[i][j] = ch - 48;
}
}
vector <vector <int>> up(n + 5, vector<int>(m + 5, 0));
vector <vector <int>> dn(n + 5, vector<int>(m + 5, 0));
for (int j = 1; j <= m; j++) {
for (int i = 1; i <= n; i++) {
up[i][j] = a[i][j] ? up[i - 1][j] + 1 : 0;
}
for (int i = n; i >= 1; i--) {
dn[i][j] = a[i][j] ? dn[i + 1][j] + 1 : 0;
}
}
vector <int> ans(m + 5, n);
for (int t = 0; t < 2; t++) {
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
if (a[i][j])
ans[1] = min(ans[1], up[i][j] + dn[i][j] - 1);
}
for (int j = 1; j <= m; j++) {
if (a[i][j] && !a[i][j - 1]) {
int min_d = n, min_u = n, k;
for (k = j; k <= m && a[i][k]; k++) {
min_d = min(min_d, dn[i][k]);
min_u = min(min_u, up[i][k]);
ans[k - j + 1] = min(ans[k - j + 1], min_d + min_u - 1);
}
ans[k - j + 1] = 0;
}
}
}
for (int i = 1; i <= n; i++) {
reverse(begin(a[i]), end(a[i]));
reverse(begin(up[i]), end(up[i]));
reverse(begin(dn[i]), end(dn[i]));
}
}
for (int i = 1; i <= m; i++) {
ans[i] = min(ans[i], ans[i - 1]);
res = max(res, i * ans[i]);
//cout << i << " --> " << ans[i] << endl;
}
cout << res << endl;
}
Compilation message
bomb.cpp: In function 'int main()':
bomb.cpp:18:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
18 | scanf("\n");
| ~~~~~^~~~~~
bomb.cpp:21:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
21 | scanf("%c", &ch);
| ~~~~~^~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
716 KB |
Output is correct |
4 |
Correct |
1 ms |
588 KB |
Output is correct |
5 |
Correct |
1 ms |
460 KB |
Output is correct |
6 |
Correct |
1 ms |
296 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
9 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
14 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
15 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
18 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
19 |
Correct |
2 ms |
384 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
1 ms |
332 KB |
Output is correct |
24 |
Correct |
1 ms |
332 KB |
Output is correct |
25 |
Correct |
2 ms |
332 KB |
Output is correct |
26 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
27 |
Incorrect |
7 ms |
1356 KB |
Output isn't correct |
28 |
Correct |
9 ms |
1756 KB |
Output is correct |
29 |
Correct |
11 ms |
1864 KB |
Output is correct |
30 |
Correct |
15 ms |
2776 KB |
Output is correct |
31 |
Correct |
13 ms |
2276 KB |
Output is correct |
32 |
Correct |
13 ms |
2496 KB |
Output is correct |
33 |
Correct |
19 ms |
2984 KB |
Output is correct |
34 |
Correct |
7 ms |
1360 KB |
Output is correct |
35 |
Correct |
16 ms |
2860 KB |
Output is correct |
36 |
Incorrect |
18 ms |
2884 KB |
Output isn't correct |
37 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
38 |
Incorrect |
661 ms |
80400 KB |
Output isn't correct |
39 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
40 |
Correct |
74 ms |
10272 KB |
Output is correct |
41 |
Correct |
1 ms |
204 KB |
Output is correct |
42 |
Correct |
1 ms |
332 KB |
Output is correct |
43 |
Correct |
645 ms |
80328 KB |
Output is correct |
44 |
Correct |
17 ms |
2976 KB |
Output is correct |
45 |
Correct |
647 ms |
80344 KB |
Output is correct |
46 |
Incorrect |
633 ms |
80212 KB |
Output isn't correct |
47 |
Correct |
638 ms |
80332 KB |
Output is correct |
48 |
Correct |
649 ms |
80328 KB |
Output is correct |
49 |
Incorrect |
675 ms |
80452 KB |
Output isn't correct |
50 |
Correct |
722 ms |
80452 KB |
Output is correct |
51 |
Correct |
641 ms |
80324 KB |
Output is correct |
52 |
Correct |
647 ms |
80328 KB |
Output is correct |
53 |
Correct |
677 ms |
80332 KB |
Output is correct |
54 |
Correct |
643 ms |
80324 KB |
Output is correct |
55 |
Correct |
629 ms |
80216 KB |
Output is correct |
56 |
Incorrect |
679 ms |
80328 KB |
Output isn't correct |
57 |
Correct |
691 ms |
80452 KB |
Output is correct |
58 |
Correct |
631 ms |
80452 KB |
Output is correct |
59 |
Correct |
639 ms |
80448 KB |
Output is correct |
60 |
Incorrect |
668 ms |
80328 KB |
Output isn't correct |
61 |
Correct |
674 ms |
80284 KB |
Output is correct |
62 |
Incorrect |
675 ms |
80328 KB |
Output isn't correct |
63 |
Incorrect |
678 ms |
80336 KB |
Output isn't correct |
64 |
Incorrect |
639 ms |
80324 KB |
Output isn't correct |
65 |
Correct |
668 ms |
80324 KB |
Output is correct |
66 |
Correct |
650 ms |
80332 KB |
Output is correct |
67 |
Correct |
689 ms |
80328 KB |
Output is correct |
68 |
Correct |
726 ms |
80540 KB |
Output is correct |
69 |
Correct |
706 ms |
80452 KB |
Output is correct |
70 |
Correct |
452 ms |
51524 KB |
Output is correct |
71 |
Correct |
687 ms |
80328 KB |
Output is correct |
72 |
Correct |
694 ms |
80332 KB |
Output is correct |
73 |
Correct |
703 ms |
80452 KB |
Output is correct |
74 |
Correct |
693 ms |
80336 KB |
Output is correct |
75 |
Correct |
678 ms |
80348 KB |
Output is correct |
76 |
Correct |
668 ms |
80336 KB |
Output is correct |
77 |
Correct |
668 ms |
80332 KB |
Output is correct |
78 |
Correct |
664 ms |
80452 KB |
Output is correct |
79 |
Correct |
648 ms |
80332 KB |
Output is correct |
80 |
Correct |
690 ms |
80332 KB |
Output is correct |
81 |
Correct |
733 ms |
80328 KB |
Output is correct |
82 |
Correct |
743 ms |
80452 KB |
Output is correct |
83 |
Correct |
721 ms |
80332 KB |
Output is correct |
84 |
Correct |
689 ms |
80328 KB |
Output is correct |
85 |
Correct |
701 ms |
80232 KB |
Output is correct |
86 |
Correct |
734 ms |
80332 KB |
Output is correct |
87 |
Incorrect |
695 ms |
80452 KB |
Output isn't correct |
88 |
Correct |
703 ms |
80348 KB |
Output is correct |
89 |
Correct |
696 ms |
80328 KB |
Output is correct |
90 |
Correct |
479 ms |
51520 KB |
Output is correct |
91 |
Correct |
738 ms |
80324 KB |
Output is correct |
92 |
Correct |
728 ms |
80328 KB |
Output is correct |
93 |
Correct |
775 ms |
80336 KB |
Output is correct |
94 |
Correct |
781 ms |
80328 KB |
Output is correct |
95 |
Correct |
714 ms |
80344 KB |
Output is correct |
96 |
Correct |
711 ms |
80444 KB |
Output is correct |
97 |
Correct |
722 ms |
80328 KB |
Output is correct |
98 |
Correct |
712 ms |
80336 KB |
Output is correct |
99 |
Correct |
689 ms |
80424 KB |
Output is correct |
100 |
Correct |
724 ms |
80328 KB |
Output is correct |