#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)
#pragma GCC optimize ("Ofast")
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;
inline void solve () {
int n, m; cin >> n >> m;
vector <string> a (n);
for (auto &i : a) cin >> i;
vector <vector <int>> p (n, vector <int> (m));
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
if (i) p[i][j] += p[i - 1][j];
if (j) p[i][j] += p[i][j - 1];
if (i && j) p[i][j] -= p[i - 1][j - 1];
p[i][j] += (a[i][j] - '0');
}
}
auto get = [&] (int x, int y, int xx, int yy) {
int res = p[xx][yy];
if (x) res -= p[x - 1][yy];
if (y) res -= p[xx][y - 1];
if (x && y) res += p[x - 1][y - 1];
return res;
};
int ans = 0;
{
int side = 1e9;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
int res = 0;
for (int q = 12; ~q; --q) {
res += pw(q);
if (j + res - 1 >= m || get(i, j, i, j + res - 1) != res) res -= pw(q);
}
if (res) umin(side, res);
j += res;
}
}
auto bad = [&] (int t) {
vector <vector <int>> f (n + 1, vector <int> (m + 1));
for (int i = 0; i + t - 1 < n; ++i) {
for (int j = 0; j + side - 1 < m; ++j) {
if (get(i, j, i + t - 1, j + side - 1) == side * t) {
++f[i][j];
--f[i + t][j];
--f[i][j + side];
++f[i + t][j + side];
}
}
}
for (int i = 0; i <= n; ++i) {
for (int j = 0; j <= m; ++j) {
if (i) f[i][j] += f[i - 1][j];
if (j) f[i][j] += f[i][j - 1];
if (i && j) f[i][j] -= f[i - 1][j - 1];
}
}
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
if (a[i][j] == '1' && !f[i][j]) return 1;
}
}
return 0;
};
int res = 0;
for (int i = 12; ~i; --i) {
res += pw(i);
if (bad(res)) res -= pw(i);
}
umax(ans, side * res);
}
{
int side = 1e9;
for (int j = 0; j < m; ++j) {
for (int i = 0; i < n; ++i) {
int res = 0;
for (int q = 12; ~q; --q) {
res += pw(q);
if (i + res - 1 >= n || get(i, j, i + res - 1, j) != res) res -= pw(q);
}
if (res) umin(side, res);
i += res;
}
}
auto bad = [&] (int t) {
vector <vector <int>> f (n + 1, vector <int> (m + 1));
for (int i = 0; i + side - 1 < n; ++i) {
for (int j = 0; j + t - 1 < m; ++j) {
if (get(i, j, i + side - 1, j + t - 1) == side * t) {
++f[i][j];
--f[i + t][j];
--f[i][j + side];
++f[i + t][j + side];
}
}
}
for (int i = 0; i <= n; ++i) {
for (int j = 0; j <= m; ++j) {
if (i) f[i][j] += f[i - 1][j];
if (j) f[i][j] += f[i][j - 1];
if (i && j) f[i][j] -= f[i - 1][j - 1];
}
}
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
if (a[i][j] == '1' && !f[i][j]) return 1;
}
}
return 0;
};
int res = 0;
for (int i = 12; ~i; --i) {
res += pw(i);
if (bad(res)) res -= pw(i);
}
umax(ans, side * res);
}
cout << ans;
}
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 |
452 KB |
Execution killed with signal 11 |
2 |
Correct |
1 ms |
316 KB |
Output is correct |
3 |
Runtime error |
4 ms |
1108 KB |
Execution killed with signal 6 |
4 |
Runtime error |
4 ms |
1108 KB |
Execution killed with signal 6 |
5 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 11 |
6 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 11 |
7 |
Runtime error |
1 ms |
340 KB |
Execution killed with signal 11 |
8 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
9 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
10 |
Runtime error |
1 ms |
456 KB |
Execution killed with signal 11 |
11 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 11 |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Incorrect |
1 ms |
216 KB |
Output isn't correct |
16 |
Runtime error |
1 ms |
444 KB |
Execution killed with signal 11 |
17 |
Runtime error |
1 ms |
448 KB |
Execution killed with signal 11 |
18 |
Incorrect |
1 ms |
324 KB |
Output isn't correct |
19 |
Incorrect |
2 ms |
340 KB |
Output isn't correct |
20 |
Incorrect |
2 ms |
340 KB |
Output isn't correct |
21 |
Incorrect |
1 ms |
320 KB |
Output isn't correct |
22 |
Incorrect |
2 ms |
340 KB |
Output isn't correct |
23 |
Runtime error |
2 ms |
716 KB |
Execution killed with signal 6 |
24 |
Incorrect |
2 ms |
332 KB |
Output isn't correct |
25 |
Runtime error |
3 ms |
592 KB |
Execution killed with signal 6 |
26 |
Runtime error |
2 ms |
604 KB |
Execution killed with signal 11 |
27 |
Runtime error |
13 ms |
2032 KB |
Execution killed with signal 11 |
28 |
Incorrect |
28 ms |
1428 KB |
Output isn't correct |
29 |
Runtime error |
19 ms |
2784 KB |
Execution killed with signal 11 |
30 |
Runtime error |
34 ms |
4004 KB |
Execution killed with signal 6 |
31 |
Incorrect |
36 ms |
1836 KB |
Output isn't correct |
32 |
Incorrect |
29 ms |
1908 KB |
Output isn't correct |
33 |
Runtime error |
32 ms |
4404 KB |
Execution killed with signal 6 |
34 |
Incorrect |
16 ms |
1264 KB |
Output isn't correct |
35 |
Incorrect |
39 ms |
2420 KB |
Output isn't correct |
36 |
Runtime error |
27 ms |
4440 KB |
Execution killed with signal 11 |
37 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 11 |
38 |
Runtime error |
551 ms |
119820 KB |
Execution killed with signal 6 |
39 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 6 |
40 |
Runtime error |
97 ms |
15272 KB |
Execution killed with signal 6 |
41 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 6 |
42 |
Runtime error |
2 ms |
712 KB |
Execution killed with signal 6 |
43 |
Runtime error |
948 ms |
119824 KB |
Execution killed with signal 11 |
44 |
Runtime error |
27 ms |
4432 KB |
Execution killed with signal 6 |
45 |
Runtime error |
961 ms |
119844 KB |
Execution killed with signal 6 |
46 |
Execution timed out |
1042 ms |
62288 KB |
Time limit exceeded |
47 |
Runtime error |
942 ms |
119780 KB |
Execution killed with signal 6 |
48 |
Execution timed out |
1031 ms |
97952 KB |
Time limit exceeded |
49 |
Runtime error |
768 ms |
119840 KB |
Execution killed with signal 11 |
50 |
Execution timed out |
1029 ms |
89948 KB |
Time limit exceeded |
51 |
Execution timed out |
1006 ms |
119804 KB |
Time limit exceeded |
52 |
Execution timed out |
1044 ms |
119716 KB |
Time limit exceeded |
53 |
Execution timed out |
1049 ms |
109972 KB |
Time limit exceeded |
54 |
Execution timed out |
1042 ms |
62288 KB |
Time limit exceeded |
55 |
Execution timed out |
1033 ms |
62508 KB |
Time limit exceeded |
56 |
Runtime error |
787 ms |
119820 KB |
Execution killed with signal 6 |
57 |
Execution timed out |
1031 ms |
62376 KB |
Time limit exceeded |
58 |
Execution timed out |
1029 ms |
62584 KB |
Time limit exceeded |
59 |
Execution timed out |
1041 ms |
62332 KB |
Time limit exceeded |
60 |
Execution timed out |
1036 ms |
62388 KB |
Time limit exceeded |
61 |
Runtime error |
671 ms |
119812 KB |
Execution killed with signal 11 |
62 |
Runtime error |
690 ms |
119876 KB |
Execution killed with signal 11 |
63 |
Runtime error |
555 ms |
119760 KB |
Execution killed with signal 11 |
64 |
Execution timed out |
1046 ms |
62380 KB |
Time limit exceeded |
65 |
Execution timed out |
1026 ms |
62524 KB |
Time limit exceeded |
66 |
Runtime error |
994 ms |
119812 KB |
Execution killed with signal 11 |
67 |
Runtime error |
996 ms |
119876 KB |
Execution killed with signal 11 |
68 |
Runtime error |
915 ms |
119824 KB |
Execution killed with signal 11 |
69 |
Execution timed out |
1036 ms |
62332 KB |
Time limit exceeded |
70 |
Incorrect |
996 ms |
40072 KB |
Output isn't correct |
71 |
Execution timed out |
1046 ms |
62428 KB |
Time limit exceeded |
72 |
Execution timed out |
1052 ms |
62316 KB |
Time limit exceeded |
73 |
Execution timed out |
1039 ms |
62344 KB |
Time limit exceeded |
74 |
Execution timed out |
1038 ms |
62352 KB |
Time limit exceeded |
75 |
Execution timed out |
1035 ms |
62336 KB |
Time limit exceeded |
76 |
Execution timed out |
1049 ms |
62456 KB |
Time limit exceeded |
77 |
Execution timed out |
1034 ms |
62368 KB |
Time limit exceeded |
78 |
Execution timed out |
1045 ms |
62316 KB |
Time limit exceeded |
79 |
Execution timed out |
1035 ms |
62352 KB |
Time limit exceeded |
80 |
Execution timed out |
1038 ms |
62332 KB |
Time limit exceeded |
81 |
Execution timed out |
1034 ms |
62344 KB |
Time limit exceeded |
82 |
Execution timed out |
1100 ms |
62300 KB |
Time limit exceeded |
83 |
Execution timed out |
1030 ms |
62344 KB |
Time limit exceeded |
84 |
Execution timed out |
1014 ms |
62336 KB |
Time limit exceeded |
85 |
Execution timed out |
1041 ms |
62364 KB |
Time limit exceeded |
86 |
Runtime error |
811 ms |
119864 KB |
Execution killed with signal 11 |
87 |
Execution timed out |
1048 ms |
62304 KB |
Time limit exceeded |
88 |
Execution timed out |
1041 ms |
62304 KB |
Time limit exceeded |
89 |
Execution timed out |
1041 ms |
62360 KB |
Time limit exceeded |
90 |
Runtime error |
760 ms |
76792 KB |
Execution killed with signal 11 |
91 |
Execution timed out |
1026 ms |
62292 KB |
Time limit exceeded |
92 |
Execution timed out |
1045 ms |
62340 KB |
Time limit exceeded |
93 |
Runtime error |
820 ms |
119900 KB |
Execution killed with signal 11 |
94 |
Execution timed out |
1046 ms |
62396 KB |
Time limit exceeded |
95 |
Execution timed out |
1037 ms |
62464 KB |
Time limit exceeded |
96 |
Execution timed out |
1027 ms |
62432 KB |
Time limit exceeded |
97 |
Runtime error |
798 ms |
119908 KB |
Execution killed with signal 11 |
98 |
Execution timed out |
1035 ms |
62344 KB |
Time limit exceeded |
99 |
Execution timed out |
1035 ms |
62500 KB |
Time limit exceeded |
100 |
Runtime error |
827 ms |
119904 KB |
Execution killed with signal 11 |