#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,popcnt,lzcnt")
#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define ui unsigned int
#define ld long double
#define pl pair<long long int, long long int>
#define boost ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ff first
#define ss second
#define sz size()
#define all(x) x.begin(), x.end()
using namespace std;
const int maxn = 1e6 + 11;
const int inf = 1e17 + 1;
const int mod = 1e9 + 7;
// const int mod = 998244353;
const int dx[] = {-1, 0, 0, 1, -1, -1, 1, 1};
const int dy[] = {0, -1, 1 , 0, -1, 1, -1, 1};
const double eps = 1e-10;
int n, m;
int pr[2505][2505], p[2505][2505];
void solve() {
cin >> n >> m;
char ch[n + 5][m + 5];
int cnt = 0;
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= m; j++) {
cin >> ch[ i ][ j ];
}
}
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= m; j++) {
pr[ i ][ j ] = pr[i - 1][ j ] + pr[ i ][j - 1] - pr[i - 1][j - 1] + (ch[ i ][ j ] - '0');
}
}
int y = m;
int x = 1;
int ans = 0;
while(x <= n && y) {
int l = 1, r = y;
int anss = 0;
while(l <= r) {
int mid = l + r >> 1;
for(int i = 0; i <= n; i++) {
for(int j = 0; j <= m; j++) {
p[ i ][ j ] = 0;
}
}
for(int i = 0; i + x <= n; i++) {
for(int j = 0; j + mid <= m; j++) {
int c = pr[i + x][j + mid] - pr[i + x][ j ] - pr[ i ][j + mid] + pr[ i ][ j ];
if(c == x * mid) {
p[i + x + 1][j + mid + 1]++;
p[i + 1][j + mid + 1]--;
p[i + x + 1][j + 1]--;
p[i + 1][j + 1]++;
}
}
}
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= m; j++) {
p[ i ][ j ] += p[i - 1][ j ] + p[ i ][j - 1] - p[i - 1][j - 1];
}
}
bool fl = true;
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= m; j++) {
if(ch[ i ][ j ] == '1' && p[ i ][ j ] == 0) {
fl = false;
break;
}
}
}
if(fl) {
anss = mid;
l = mid + 1;
}
else {
r = mid - 1;
}
}
y = anss;
ans = max(ans, x * y);
x++;
}
cout << ans;
}
signed main() {
// freopen("sum.in", "r", stdin);
// freopen("sum.out", "w", stdout);
boost;
int tt = 1;
// cin >> tt;
for(int i = 1; i <= tt; i++) {
// cout << "Case " << i << ":\n";
solve();
}
}
Compilation message
bomb.cpp: In function 'void solve()':
bomb.cpp:55:25: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
55 | int mid = l + r >> 1;
| ~~^~~
bomb.cpp:35:9: warning: unused variable 'cnt' [-Wunused-variable]
35 | int cnt = 0;
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
14 ms |
58132 KB |
Output is correct |
4 |
Correct |
15 ms |
58456 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
1 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
17 |
Correct |
1 ms |
2652 KB |
Output is correct |
18 |
Correct |
1 ms |
2648 KB |
Output is correct |
19 |
Correct |
1 ms |
2908 KB |
Output is correct |
20 |
Correct |
1 ms |
2908 KB |
Output is correct |
21 |
Correct |
1 ms |
2652 KB |
Output is correct |
22 |
Correct |
1 ms |
2908 KB |
Output is correct |
23 |
Correct |
3 ms |
2908 KB |
Output is correct |
24 |
Correct |
2 ms |
2904 KB |
Output is correct |
25 |
Correct |
3 ms |
2904 KB |
Output is correct |
26 |
Correct |
3 ms |
2908 KB |
Output is correct |
27 |
Correct |
6 ms |
8568 KB |
Output is correct |
28 |
Correct |
11 ms |
8796 KB |
Output is correct |
29 |
Correct |
240 ms |
11380 KB |
Output is correct |
30 |
Correct |
80 ms |
14372 KB |
Output is correct |
31 |
Correct |
65 ms |
11352 KB |
Output is correct |
32 |
Correct |
61 ms |
11608 KB |
Output is correct |
33 |
Correct |
117 ms |
14368 KB |
Output is correct |
34 |
Correct |
9 ms |
10840 KB |
Output is correct |
35 |
Correct |
26 ms |
14172 KB |
Output is correct |
36 |
Correct |
253 ms |
14364 KB |
Output is correct |
37 |
Correct |
1 ms |
2392 KB |
Output is correct |
38 |
Execution timed out |
1039 ms |
104464 KB |
Time limit exceeded |
39 |
Correct |
1 ms |
2392 KB |
Output is correct |
40 |
Execution timed out |
1090 ms |
31836 KB |
Time limit exceeded |
41 |
Correct |
1 ms |
2392 KB |
Output is correct |
42 |
Correct |
8 ms |
2908 KB |
Output is correct |
43 |
Execution timed out |
1082 ms |
104532 KB |
Time limit exceeded |
44 |
Correct |
821 ms |
14368 KB |
Output is correct |
45 |
Execution timed out |
1070 ms |
104636 KB |
Time limit exceeded |
46 |
Execution timed out |
1053 ms |
104856 KB |
Time limit exceeded |
47 |
Execution timed out |
1064 ms |
104496 KB |
Time limit exceeded |
48 |
Execution timed out |
1008 ms |
104528 KB |
Time limit exceeded |
49 |
Execution timed out |
1028 ms |
104456 KB |
Time limit exceeded |
50 |
Execution timed out |
1039 ms |
104636 KB |
Time limit exceeded |
51 |
Execution timed out |
1034 ms |
104880 KB |
Time limit exceeded |
52 |
Execution timed out |
1024 ms |
104500 KB |
Time limit exceeded |
53 |
Execution timed out |
1039 ms |
104644 KB |
Time limit exceeded |
54 |
Execution timed out |
1054 ms |
104532 KB |
Time limit exceeded |
55 |
Execution timed out |
1066 ms |
104532 KB |
Time limit exceeded |
56 |
Execution timed out |
1046 ms |
104636 KB |
Time limit exceeded |
57 |
Execution timed out |
1055 ms |
104620 KB |
Time limit exceeded |
58 |
Execution timed out |
1043 ms |
104532 KB |
Time limit exceeded |
59 |
Execution timed out |
1033 ms |
104412 KB |
Time limit exceeded |
60 |
Execution timed out |
1068 ms |
104636 KB |
Time limit exceeded |
61 |
Execution timed out |
1069 ms |
104532 KB |
Time limit exceeded |
62 |
Execution timed out |
1033 ms |
104532 KB |
Time limit exceeded |
63 |
Execution timed out |
1058 ms |
104532 KB |
Time limit exceeded |
64 |
Execution timed out |
1043 ms |
104528 KB |
Time limit exceeded |
65 |
Execution timed out |
1079 ms |
104532 KB |
Time limit exceeded |
66 |
Execution timed out |
1042 ms |
104628 KB |
Time limit exceeded |
67 |
Execution timed out |
1049 ms |
104532 KB |
Time limit exceeded |
68 |
Execution timed out |
1010 ms |
104528 KB |
Time limit exceeded |
69 |
Execution timed out |
1043 ms |
104388 KB |
Time limit exceeded |
70 |
Execution timed out |
1051 ms |
84784 KB |
Time limit exceeded |
71 |
Execution timed out |
1033 ms |
104528 KB |
Time limit exceeded |
72 |
Execution timed out |
1067 ms |
104384 KB |
Time limit exceeded |
73 |
Execution timed out |
1014 ms |
104620 KB |
Time limit exceeded |
74 |
Execution timed out |
1035 ms |
104528 KB |
Time limit exceeded |
75 |
Execution timed out |
1041 ms |
104532 KB |
Time limit exceeded |
76 |
Execution timed out |
1004 ms |
104528 KB |
Time limit exceeded |
77 |
Execution timed out |
1052 ms |
104380 KB |
Time limit exceeded |
78 |
Execution timed out |
1044 ms |
104784 KB |
Time limit exceeded |
79 |
Execution timed out |
1025 ms |
104528 KB |
Time limit exceeded |
80 |
Execution timed out |
1029 ms |
104528 KB |
Time limit exceeded |
81 |
Execution timed out |
1046 ms |
108692 KB |
Time limit exceeded |
82 |
Execution timed out |
1042 ms |
108532 KB |
Time limit exceeded |
83 |
Execution timed out |
1051 ms |
108528 KB |
Time limit exceeded |
84 |
Execution timed out |
1089 ms |
108424 KB |
Time limit exceeded |
85 |
Execution timed out |
1034 ms |
108436 KB |
Time limit exceeded |
86 |
Execution timed out |
1048 ms |
108572 KB |
Time limit exceeded |
87 |
Execution timed out |
1012 ms |
108436 KB |
Time limit exceeded |
88 |
Execution timed out |
1097 ms |
108528 KB |
Time limit exceeded |
89 |
Execution timed out |
1040 ms |
108620 KB |
Time limit exceeded |
90 |
Execution timed out |
1047 ms |
87236 KB |
Time limit exceeded |
91 |
Execution timed out |
1024 ms |
108492 KB |
Time limit exceeded |
92 |
Execution timed out |
1063 ms |
108624 KB |
Time limit exceeded |
93 |
Execution timed out |
1045 ms |
108628 KB |
Time limit exceeded |
94 |
Execution timed out |
1101 ms |
108412 KB |
Time limit exceeded |
95 |
Execution timed out |
1057 ms |
104620 KB |
Time limit exceeded |
96 |
Execution timed out |
1060 ms |
104628 KB |
Time limit exceeded |
97 |
Execution timed out |
1035 ms |
104624 KB |
Time limit exceeded |
98 |
Execution timed out |
1047 ms |
104620 KB |
Time limit exceeded |
99 |
Execution timed out |
1040 ms |
104528 KB |
Time limit exceeded |
100 |
Execution timed out |
1059 ms |
104532 KB |
Time limit exceeded |