#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define fr first
#define sc second
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define endl '\n'
#define sz(x) (int)((x).size())
#define vec vector
#define pw(x) (1ll << x)
using namespace std;
using namespace __gnu_pbds;
template <typename T> inline bool umin (T &a, const T &b) { if (a > b) { a = b; return 1; } return 0; }
template <typename T> inline bool umax (T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
const int inf = 1e9 + 17;
inline void solve () {
int n, m; cin >> n >> m;
vec <string> a (n);
for (auto &i : a) cin >> i;
vec <int> mx (m + 2, inf);
for (int iter = 0; iter < 2; ++iter) {
vec <vec <int>> p (n, vec <int> (m)), s (n, vec <int> (m));
for (int j = 0; j < m; ++j) {
p[0][j] = (a[0][j] == '1');
for (int i = 1; i < n; ++i) {
if (a[i][j] == '1') p[i][j] = p[i - 1][j] + 1;
}
s[n - 1][j] = (a[n - 1][j] == '1');
for (int i = n - 2; ~i; --i) {
if (a[i][j] == '1') s[i][j] = s[i + 1][j] + 1;
}
for (int i = 0; i < n; ++i) if (a[i][j] == '1') umin(mx[1], p[i][j] + s[i][j] - 1);
}
for (int i = 0; i < n; ++i) {
for (int l = 0, r = 0; r < m; ) {
while (r < m && a[i][r] == '1') ++r;
if (l == r) {
++l, ++r;
continue;
}
int mn_down = inf, mn_up = inf;
for (int q = l; q < r; ++q) {
umin(mn_up, p[i][q]);
umin(mn_down, s[i][q]);
umin(mx[q - l + 1], mn_down + mn_up - 1);
}
umin(mx[r - l + 1], 0);
l = r;
}
}
for (auto &i : a) reverse(all(i));
}
int ans = 0;
bool ok = 0;
for (int i = 1; i <= m; ++i) {
umin(mx[i], mx[i - 1]);
if (i > 1 && mx[i] != mx[i - 1] && mx[i] > 0) ok = 1;
umax(ans, mx[i] * i);
}
assert(ok);
cout << ans << endl;
}
signed main () {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifdef LOCAL
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif// LOCAL
int t = 1; //cin >> t;
while (t--) solve();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 6 |
2 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 6 |
3 |
Runtime error |
2 ms |
1108 KB |
Execution killed with signal 6 |
4 |
Runtime error |
2 ms |
1108 KB |
Execution killed with signal 6 |
5 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 6 |
6 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 6 |
7 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 6 |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 6 |
14 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 6 |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 6 |
17 |
Runtime error |
1 ms |
596 KB |
Execution killed with signal 6 |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
0 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Runtime error |
1 ms |
596 KB |
Execution killed with signal 6 |
27 |
Runtime error |
3 ms |
980 KB |
Execution killed with signal 6 |
28 |
Correct |
2 ms |
1240 KB |
Output is correct |
29 |
Correct |
4 ms |
1380 KB |
Output is correct |
30 |
Correct |
5 ms |
2004 KB |
Output is correct |
31 |
Correct |
3 ms |
1620 KB |
Output is correct |
32 |
Correct |
5 ms |
1644 KB |
Output is correct |
33 |
Correct |
5 ms |
2132 KB |
Output is correct |
34 |
Correct |
2 ms |
1040 KB |
Output is correct |
35 |
Correct |
5 ms |
2132 KB |
Output is correct |
36 |
Runtime error |
7 ms |
2132 KB |
Execution killed with signal 6 |
37 |
Correct |
1 ms |
212 KB |
Output is correct |
38 |
Runtime error |
666 ms |
56164 KB |
Execution killed with signal 6 |
39 |
Correct |
0 ms |
212 KB |
Output is correct |
40 |
Correct |
41 ms |
7252 KB |
Output is correct |
41 |
Correct |
0 ms |
212 KB |
Output is correct |
42 |
Correct |
1 ms |
340 KB |
Output is correct |
43 |
Runtime error |
504 ms |
56168 KB |
Execution killed with signal 6 |
44 |
Correct |
6 ms |
2132 KB |
Output is correct |
45 |
Correct |
473 ms |
56192 KB |
Output is correct |
46 |
Runtime error |
472 ms |
56208 KB |
Execution killed with signal 6 |
47 |
Correct |
480 ms |
56212 KB |
Output is correct |
48 |
Correct |
433 ms |
56160 KB |
Output is correct |
49 |
Runtime error |
632 ms |
56104 KB |
Execution killed with signal 6 |
50 |
Correct |
470 ms |
56192 KB |
Output is correct |
51 |
Correct |
473 ms |
56280 KB |
Output is correct |
52 |
Correct |
512 ms |
56244 KB |
Output is correct |
53 |
Correct |
467 ms |
56220 KB |
Output is correct |
54 |
Correct |
329 ms |
56152 KB |
Output is correct |
55 |
Correct |
332 ms |
56196 KB |
Output is correct |
56 |
Runtime error |
631 ms |
56220 KB |
Execution killed with signal 6 |
57 |
Correct |
296 ms |
56188 KB |
Output is correct |
58 |
Correct |
340 ms |
56192 KB |
Output is correct |
59 |
Correct |
308 ms |
56256 KB |
Output is correct |
60 |
Runtime error |
450 ms |
56228 KB |
Execution killed with signal 6 |
61 |
Runtime error |
708 ms |
56164 KB |
Execution killed with signal 6 |
62 |
Runtime error |
734 ms |
56160 KB |
Execution killed with signal 6 |
63 |
Runtime error |
723 ms |
56164 KB |
Execution killed with signal 6 |
64 |
Runtime error |
393 ms |
56164 KB |
Execution killed with signal 6 |
65 |
Correct |
469 ms |
56176 KB |
Output is correct |
66 |
Correct |
483 ms |
56164 KB |
Output is correct |
67 |
Correct |
568 ms |
56204 KB |
Output is correct |
68 |
Correct |
541 ms |
56160 KB |
Output is correct |
69 |
Correct |
360 ms |
56196 KB |
Output is correct |
70 |
Correct |
129 ms |
36116 KB |
Output is correct |
71 |
Correct |
293 ms |
56240 KB |
Output is correct |
72 |
Correct |
320 ms |
56200 KB |
Output is correct |
73 |
Correct |
372 ms |
56204 KB |
Output is correct |
74 |
Correct |
375 ms |
56168 KB |
Output is correct |
75 |
Correct |
391 ms |
56172 KB |
Output is correct |
76 |
Correct |
382 ms |
56248 KB |
Output is correct |
77 |
Correct |
387 ms |
56200 KB |
Output is correct |
78 |
Correct |
415 ms |
56104 KB |
Output is correct |
79 |
Correct |
205 ms |
56176 KB |
Output is correct |
80 |
Correct |
215 ms |
56192 KB |
Output is correct |
81 |
Correct |
253 ms |
56156 KB |
Output is correct |
82 |
Correct |
403 ms |
56268 KB |
Output is correct |
83 |
Correct |
405 ms |
56164 KB |
Output is correct |
84 |
Correct |
234 ms |
56164 KB |
Output is correct |
85 |
Correct |
407 ms |
56192 KB |
Output is correct |
86 |
Correct |
671 ms |
56164 KB |
Output is correct |
87 |
Correct |
381 ms |
56300 KB |
Output is correct |
88 |
Correct |
390 ms |
56244 KB |
Output is correct |
89 |
Correct |
467 ms |
56164 KB |
Output is correct |
90 |
Correct |
203 ms |
36116 KB |
Output is correct |
91 |
Correct |
430 ms |
56164 KB |
Output is correct |
92 |
Correct |
469 ms |
56268 KB |
Output is correct |
93 |
Correct |
638 ms |
56160 KB |
Output is correct |
94 |
Correct |
481 ms |
56280 KB |
Output is correct |
95 |
Correct |
363 ms |
56292 KB |
Output is correct |
96 |
Correct |
382 ms |
56248 KB |
Output is correct |
97 |
Correct |
644 ms |
56216 KB |
Output is correct |
98 |
Correct |
379 ms |
56164 KB |
Output is correct |
99 |
Correct |
450 ms |
56220 KB |
Output is correct |
100 |
Correct |
647 ms |
56184 KB |
Output is correct |