/*
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC target ("avx2")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
*/
#include<bits/stdc++.h>
#define ld long double
#define sz(v) (int)v.size()
#define ll long long
#define pb push_back
#define x first
#define y second
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define nl "\n"
using namespace std;
const int N = (int)25e2 + 7; // make sure this is right
const int M = (int)1e6 + 7;
const int B = 351;
const int inf = (int)2e9 + 7;
const ll INF = (ll)3e18 + 7;
const ll MOD = (ll)1e9 + 7; // make sure this is right
bool bit(int x, int i) {
return x >> i & 1;
}
int mult(int x, int y) {
return 1ll * x * y % MOD;
}
int sum(int x, int y) {
x += y;
if(x >= MOD) x -= MOD;
return x;
}
int n, m, p[N][N], e[N][N];
char a[N][N];
int get(int x1, int y1, int x2, int y2) {
return (p[x2][y2] - p[x1 - 1][y2] - p[x2][y1 - 1] + p[x1 - 1][y1 - 1]);
}
void solve() {
cin >> n >> m;
for(int i = 1; i <= n; ++i) {
for(int j = 1; j <= m; ++j) {
cin >> a[i][j];
p[i][j] = p[i - 1][j] + p[i][j - 1] - p[i - 1][j - 1] + (a[i][j] == '1');
}
}
int ans = 0;
for(int h = 1; h <= n; ++h) {
int l = 1, r = m;
while(l <= r) {
int w = (l + r) >> 1;
for(int i = 1; i <= n - h + 1; ++i) {
for(int j = 1; j <= m - w + 1; ++j) {
int ii = i + h - 1, jj = j + w - 1;
int x = get(i, j, ii, jj);
if(x == h * w) {
e[i][j]++;
e[i][jj + 1]--;
e[ii + 1][j]--;
e[ii + 1][jj + 1]++;
}
}
}
bool ok = 1;
for(int i = 1; i <= n && ok; ++i) {
for(int j = 1; j <= m && ok; ++j) {
e[i][j] += e[i - 1][j];
e[i][j] += e[i][j - 1];
e[i][j] -= e[i - 1][j - 1];
if(a[i][j] == '1') {
ok &= (e[i][j] > 0);
}
}
}
for(int i = 1; i <= n; ++i) {
for(int j = 1; j <= m; ++j) {
e[i][j] = 0;
}
}
if(ok) {
ans = max(ans, h * w);
l = w + 1;
} else
r = w - 1;
}
}
cout << ans << "\n";
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int test = 1;
//cin >> test;
for(int i = 1; i <= test; ++i) {
//cout << "Case #" << i << ": ";
solve();
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
468 KB |
Output is correct |
3 |
Correct |
118 ms |
26536 KB |
Output is correct |
4 |
Correct |
99 ms |
26540 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
1 ms |
468 KB |
Output is correct |
10 |
Correct |
1 ms |
468 KB |
Output is correct |
11 |
Correct |
1 ms |
468 KB |
Output is correct |
12 |
Correct |
1 ms |
468 KB |
Output is correct |
13 |
Correct |
1 ms |
468 KB |
Output is correct |
14 |
Correct |
1 ms |
468 KB |
Output is correct |
15 |
Correct |
1 ms |
468 KB |
Output is correct |
16 |
Correct |
1 ms |
468 KB |
Output is correct |
17 |
Correct |
2 ms |
980 KB |
Output is correct |
18 |
Correct |
2 ms |
1108 KB |
Output is correct |
19 |
Correct |
4 ms |
1364 KB |
Output is correct |
20 |
Correct |
5 ms |
1364 KB |
Output is correct |
21 |
Correct |
2 ms |
852 KB |
Output is correct |
22 |
Correct |
3 ms |
1108 KB |
Output is correct |
23 |
Correct |
7 ms |
1492 KB |
Output is correct |
24 |
Correct |
4 ms |
1236 KB |
Output is correct |
25 |
Correct |
9 ms |
1364 KB |
Output is correct |
26 |
Correct |
9 ms |
1464 KB |
Output is correct |
27 |
Correct |
214 ms |
4056 KB |
Output is correct |
28 |
Correct |
165 ms |
4224 KB |
Output is correct |
29 |
Correct |
565 ms |
5388 KB |
Output is correct |
30 |
Correct |
599 ms |
6356 KB |
Output is correct |
31 |
Correct |
365 ms |
5000 KB |
Output is correct |
32 |
Correct |
543 ms |
5800 KB |
Output is correct |
33 |
Correct |
820 ms |
6636 KB |
Output is correct |
34 |
Correct |
185 ms |
4728 KB |
Output is correct |
35 |
Correct |
602 ms |
6632 KB |
Output is correct |
36 |
Correct |
905 ms |
6648 KB |
Output is correct |
37 |
Correct |
1 ms |
468 KB |
Output is correct |
38 |
Execution timed out |
1099 ms |
55400 KB |
Time limit exceeded |
39 |
Correct |
1 ms |
468 KB |
Output is correct |
40 |
Execution timed out |
1092 ms |
15552 KB |
Time limit exceeded |
41 |
Correct |
0 ms |
468 KB |
Output is correct |
42 |
Correct |
14 ms |
1464 KB |
Output is correct |
43 |
Execution timed out |
1074 ms |
55432 KB |
Time limit exceeded |
44 |
Execution timed out |
1090 ms |
6624 KB |
Time limit exceeded |
45 |
Execution timed out |
1092 ms |
55484 KB |
Time limit exceeded |
46 |
Execution timed out |
1099 ms |
55496 KB |
Time limit exceeded |
47 |
Execution timed out |
1095 ms |
55500 KB |
Time limit exceeded |
48 |
Execution timed out |
1091 ms |
55464 KB |
Time limit exceeded |
49 |
Execution timed out |
1079 ms |
55488 KB |
Time limit exceeded |
50 |
Execution timed out |
1090 ms |
55484 KB |
Time limit exceeded |
51 |
Execution timed out |
1096 ms |
55404 KB |
Time limit exceeded |
52 |
Execution timed out |
1089 ms |
55508 KB |
Time limit exceeded |
53 |
Execution timed out |
1082 ms |
55504 KB |
Time limit exceeded |
54 |
Execution timed out |
1090 ms |
55412 KB |
Time limit exceeded |
55 |
Execution timed out |
1099 ms |
55496 KB |
Time limit exceeded |
56 |
Execution timed out |
1085 ms |
55412 KB |
Time limit exceeded |
57 |
Execution timed out |
1094 ms |
55436 KB |
Time limit exceeded |
58 |
Execution timed out |
1087 ms |
55500 KB |
Time limit exceeded |
59 |
Execution timed out |
1095 ms |
55444 KB |
Time limit exceeded |
60 |
Execution timed out |
1089 ms |
55484 KB |
Time limit exceeded |
61 |
Execution timed out |
1083 ms |
55452 KB |
Time limit exceeded |
62 |
Execution timed out |
1091 ms |
55496 KB |
Time limit exceeded |
63 |
Execution timed out |
1091 ms |
55536 KB |
Time limit exceeded |
64 |
Execution timed out |
1092 ms |
55500 KB |
Time limit exceeded |
65 |
Execution timed out |
1090 ms |
55508 KB |
Time limit exceeded |
66 |
Execution timed out |
1092 ms |
55420 KB |
Time limit exceeded |
67 |
Execution timed out |
1095 ms |
55392 KB |
Time limit exceeded |
68 |
Execution timed out |
1089 ms |
55480 KB |
Time limit exceeded |
69 |
Execution timed out |
1093 ms |
55500 KB |
Time limit exceeded |
70 |
Execution timed out |
1097 ms |
44460 KB |
Time limit exceeded |
71 |
Execution timed out |
1089 ms |
55500 KB |
Time limit exceeded |
72 |
Execution timed out |
1098 ms |
55404 KB |
Time limit exceeded |
73 |
Execution timed out |
1097 ms |
55380 KB |
Time limit exceeded |
74 |
Execution timed out |
1090 ms |
55440 KB |
Time limit exceeded |
75 |
Execution timed out |
1094 ms |
55468 KB |
Time limit exceeded |
76 |
Execution timed out |
1094 ms |
55468 KB |
Time limit exceeded |
77 |
Execution timed out |
1092 ms |
55424 KB |
Time limit exceeded |
78 |
Execution timed out |
1096 ms |
55444 KB |
Time limit exceeded |
79 |
Execution timed out |
1084 ms |
55408 KB |
Time limit exceeded |
80 |
Execution timed out |
1084 ms |
55472 KB |
Time limit exceeded |
81 |
Execution timed out |
1096 ms |
55388 KB |
Time limit exceeded |
82 |
Execution timed out |
1090 ms |
55412 KB |
Time limit exceeded |
83 |
Execution timed out |
1086 ms |
55424 KB |
Time limit exceeded |
84 |
Execution timed out |
1094 ms |
55500 KB |
Time limit exceeded |
85 |
Execution timed out |
1087 ms |
55460 KB |
Time limit exceeded |
86 |
Execution timed out |
1084 ms |
55500 KB |
Time limit exceeded |
87 |
Execution timed out |
1098 ms |
55500 KB |
Time limit exceeded |
88 |
Execution timed out |
1092 ms |
55464 KB |
Time limit exceeded |
89 |
Execution timed out |
1096 ms |
55504 KB |
Time limit exceeded |
90 |
Execution timed out |
1101 ms |
44352 KB |
Time limit exceeded |
91 |
Execution timed out |
1091 ms |
55504 KB |
Time limit exceeded |
92 |
Execution timed out |
1099 ms |
55464 KB |
Time limit exceeded |
93 |
Execution timed out |
1099 ms |
55476 KB |
Time limit exceeded |
94 |
Execution timed out |
1093 ms |
55492 KB |
Time limit exceeded |
95 |
Execution timed out |
1097 ms |
55400 KB |
Time limit exceeded |
96 |
Execution timed out |
1083 ms |
55492 KB |
Time limit exceeded |
97 |
Execution timed out |
1097 ms |
55464 KB |
Time limit exceeded |
98 |
Execution timed out |
1090 ms |
55500 KB |
Time limit exceeded |
99 |
Execution timed out |
1095 ms |
55500 KB |
Time limit exceeded |
100 |
Execution timed out |
1094 ms |
55500 KB |
Time limit exceeded |