#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 |
0 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 |
1 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 |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
0 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 |
1364 KB |
Output is correct |
30 |
Correct |
4 ms |
2004 KB |
Output is correct |
31 |
Correct |
3 ms |
1620 KB |
Output is correct |
32 |
Correct |
4 ms |
1748 KB |
Output is correct |
33 |
Correct |
4 ms |
2132 KB |
Output is correct |
34 |
Correct |
2 ms |
1040 KB |
Output is correct |
35 |
Correct |
4 ms |
2132 KB |
Output is correct |
36 |
Runtime error |
9 ms |
2132 KB |
Execution killed with signal 6 |
37 |
Correct |
0 ms |
212 KB |
Output is correct |
38 |
Runtime error |
631 ms |
56200 KB |
Execution killed with signal 6 |
39 |
Correct |
0 ms |
212 KB |
Output is correct |
40 |
Correct |
44 ms |
7260 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 |
527 ms |
56168 KB |
Execution killed with signal 6 |
44 |
Correct |
5 ms |
2132 KB |
Output is correct |
45 |
Correct |
487 ms |
56228 KB |
Output is correct |
46 |
Runtime error |
486 ms |
56260 KB |
Execution killed with signal 6 |
47 |
Correct |
534 ms |
56164 KB |
Output is correct |
48 |
Correct |
429 ms |
56188 KB |
Output is correct |
49 |
Runtime error |
648 ms |
56188 KB |
Execution killed with signal 6 |
50 |
Correct |
420 ms |
56220 KB |
Output is correct |
51 |
Correct |
467 ms |
56160 KB |
Output is correct |
52 |
Correct |
479 ms |
56296 KB |
Output is correct |
53 |
Correct |
486 ms |
56084 KB |
Output is correct |
54 |
Correct |
331 ms |
56196 KB |
Output is correct |
55 |
Correct |
354 ms |
56196 KB |
Output is correct |
56 |
Runtime error |
663 ms |
56168 KB |
Execution killed with signal 6 |
57 |
Correct |
334 ms |
56204 KB |
Output is correct |
58 |
Correct |
356 ms |
56160 KB |
Output is correct |
59 |
Correct |
295 ms |
56160 KB |
Output is correct |
60 |
Runtime error |
389 ms |
56168 KB |
Execution killed with signal 6 |
61 |
Runtime error |
653 ms |
56196 KB |
Execution killed with signal 6 |
62 |
Runtime error |
674 ms |
56168 KB |
Execution killed with signal 6 |
63 |
Runtime error |
664 ms |
56164 KB |
Execution killed with signal 6 |
64 |
Runtime error |
410 ms |
56160 KB |
Execution killed with signal 6 |
65 |
Correct |
489 ms |
56164 KB |
Output is correct |
66 |
Correct |
505 ms |
56192 KB |
Output is correct |
67 |
Correct |
559 ms |
56160 KB |
Output is correct |
68 |
Correct |
606 ms |
56160 KB |
Output is correct |
69 |
Correct |
614 ms |
56164 KB |
Output is correct |
70 |
Correct |
185 ms |
36072 KB |
Output is correct |
71 |
Correct |
291 ms |
56140 KB |
Output is correct |
72 |
Correct |
341 ms |
56168 KB |
Output is correct |
73 |
Correct |
326 ms |
56164 KB |
Output is correct |
74 |
Correct |
376 ms |
56160 KB |
Output is correct |
75 |
Correct |
334 ms |
56164 KB |
Output is correct |
76 |
Correct |
381 ms |
56336 KB |
Output is correct |
77 |
Correct |
341 ms |
56196 KB |
Output is correct |
78 |
Correct |
336 ms |
56196 KB |
Output is correct |
79 |
Correct |
194 ms |
56160 KB |
Output is correct |
80 |
Correct |
193 ms |
56208 KB |
Output is correct |
81 |
Correct |
278 ms |
56164 KB |
Output is correct |
82 |
Correct |
373 ms |
56160 KB |
Output is correct |
83 |
Correct |
364 ms |
56196 KB |
Output is correct |
84 |
Correct |
200 ms |
56260 KB |
Output is correct |
85 |
Correct |
360 ms |
56168 KB |
Output is correct |
86 |
Correct |
666 ms |
56168 KB |
Output is correct |
87 |
Correct |
346 ms |
56160 KB |
Output is correct |
88 |
Correct |
381 ms |
56160 KB |
Output is correct |
89 |
Correct |
408 ms |
56160 KB |
Output is correct |
90 |
Correct |
238 ms |
36060 KB |
Output is correct |
91 |
Correct |
447 ms |
56208 KB |
Output is correct |
92 |
Correct |
442 ms |
56164 KB |
Output is correct |
93 |
Correct |
689 ms |
56160 KB |
Output is correct |
94 |
Correct |
448 ms |
56160 KB |
Output is correct |
95 |
Correct |
385 ms |
56164 KB |
Output is correct |
96 |
Correct |
371 ms |
56164 KB |
Output is correct |
97 |
Correct |
626 ms |
56160 KB |
Output is correct |
98 |
Correct |
389 ms |
56184 KB |
Output is correct |
99 |
Correct |
459 ms |
56164 KB |
Output is correct |
100 |
Correct |
617 ms |
56164 KB |
Output is correct |