/******************************************************************************
Welcome to GDB Online.
GDB online is an online compiler and debugger tool for C, C++, Python, Java, PHP, Ruby, Perl,
C#, OCaml, VB, Swift, Pascal, Fortran, Haskell, Objective-C, Assembly, HTML, CSS, JS, SQLite, Prolog.
Code, Compile, Run and Debug online from anywhere in world.
*******************************************************************************/
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("avx2,tune=native")
const int N = 3e3 + 5;
int n, m;
int mp[N][N], pre[N][N];
bool bisa(int w, int h){
int mpt[n + 1][m + 1];
int sz = w*h;
memset(mpt, 0, sizeof(mpt));
for(int i = 1; i + w - 1 <= n; i++){
for(int j = 1; j + h - 1 <= m; j++){
int bi = i + w - 1, bj = j + h - 1;
if(pre[bi][bj] + pre[i - 1][j - 1] - pre[i - 1][bj] - pre[bi][j - 1] == 0){
mpt[i][j] = 1;
}
}
}
for(int i = 1; i <= n; i++){
for(int j = 1; j <= m; j++){
mpt[i][j] += mpt[i][j - 1];
}
}
for(int j = 1; j <= m; j++){
for(int i = 1; i <= n; i++){
mpt[i][j] += mpt[i - 1][j];
}
}
for(int i = 1; i <= n; i++){
for(int j = 1; j <= m; j++){
if(mp[i][j] == 0){
int bi = max(i - w, 0);
int bj = max(j - h, 0);
if(mpt[i][j] + mpt[bi][bj] - mpt[bi][j] - mpt[i][bj] == 0){
return false;
}
}
}
}
return true;
}
void solve(){
cin >> n >> m;
memset(mp, 0, sizeof(mp));
memset(pre, 0, sizeof(pre));
string s;
int mw = n, cw = 0, mh = m, ch = 0;
for(int i = 1; i <= n; i++){
cin >> s;
ch = 0;
for(int j = 1; j <= m; j++){
if(s[j - 1] == '0'){
mp[i][j] = 1;
if(ch != 0){
mh = min(mh, ch);
}
ch = 0;
}else{
ch++;
}
}
if(ch != 0){
mh = min(mh, ch);
}
}
for(int i = 1; i <= n; i++){
for(int j = 1; j <= m; j++){
pre[i][j] = pre[i][j - 1] + mp[i][j];
}
}
for(int j = 1; j <= m; j++){
cw = 0;
for(int i = 1; i <= n; i++){
pre[i][j] += pre[i - 1][j];
if(mp[i][j] == 0){
cw++;
}else{
if(cw != 0){
mw = min(mw, cw);
}
cw = 0;
}
}
if(cw != 0){
mw = min(mw, cw);
}
}
int mx = 1;
for(int i = 1; i <= mw; i++){
int l = ceil((double)mx/i), r = mh;
while(l <= r){
int mid = (l + r)/2;
if(bisa(i, mid)){
l = mid + 1;
}else{
r = mid - 1;
}
}
mx = max(mx, i*r);
}
cout << mx << endl;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(NULL);
int t = 1;
while(t--){
solve();
}
return 0;
}
Compilation message
bomb.cpp: In function 'bool bisa(int, int)':
bomb.cpp:22:9: warning: unused variable 'sz' [-Wunused-variable]
22 | int sz = w*h;
| ^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
24 ms |
70996 KB |
Output is correct |
2 |
Correct |
24 ms |
70980 KB |
Output is correct |
3 |
Correct |
26 ms |
70884 KB |
Output is correct |
4 |
Correct |
29 ms |
70904 KB |
Output is correct |
5 |
Correct |
26 ms |
70956 KB |
Output is correct |
6 |
Correct |
25 ms |
70932 KB |
Output is correct |
7 |
Correct |
25 ms |
70892 KB |
Output is correct |
8 |
Correct |
25 ms |
70956 KB |
Output is correct |
9 |
Correct |
24 ms |
70988 KB |
Output is correct |
10 |
Correct |
24 ms |
70940 KB |
Output is correct |
11 |
Correct |
24 ms |
70996 KB |
Output is correct |
12 |
Correct |
23 ms |
70920 KB |
Output is correct |
13 |
Correct |
25 ms |
70864 KB |
Output is correct |
14 |
Correct |
25 ms |
70996 KB |
Output is correct |
15 |
Correct |
25 ms |
70988 KB |
Output is correct |
16 |
Correct |
24 ms |
70924 KB |
Output is correct |
17 |
Correct |
24 ms |
71012 KB |
Output is correct |
18 |
Correct |
24 ms |
70968 KB |
Output is correct |
19 |
Correct |
30 ms |
70988 KB |
Output is correct |
20 |
Correct |
27 ms |
71044 KB |
Output is correct |
21 |
Correct |
25 ms |
70944 KB |
Output is correct |
22 |
Correct |
25 ms |
70996 KB |
Output is correct |
23 |
Correct |
27 ms |
70936 KB |
Output is correct |
24 |
Correct |
26 ms |
70960 KB |
Output is correct |
25 |
Correct |
28 ms |
70996 KB |
Output is correct |
26 |
Correct |
29 ms |
71004 KB |
Output is correct |
27 |
Correct |
27 ms |
71364 KB |
Output is correct |
28 |
Correct |
31 ms |
71452 KB |
Output is correct |
29 |
Correct |
189 ms |
71504 KB |
Output is correct |
30 |
Correct |
412 ms |
71912 KB |
Output is correct |
31 |
Correct |
224 ms |
71636 KB |
Output is correct |
32 |
Correct |
269 ms |
71868 KB |
Output is correct |
33 |
Correct |
597 ms |
71980 KB |
Output is correct |
34 |
Correct |
31 ms |
71276 KB |
Output is correct |
35 |
Correct |
96 ms |
71972 KB |
Output is correct |
36 |
Correct |
159 ms |
71884 KB |
Output is correct |
37 |
Correct |
25 ms |
70860 KB |
Output is correct |
38 |
Execution timed out |
1079 ms |
99900 KB |
Time limit exceeded |
39 |
Correct |
27 ms |
70888 KB |
Output is correct |
40 |
Execution timed out |
1081 ms |
74752 KB |
Time limit exceeded |
41 |
Correct |
25 ms |
70996 KB |
Output is correct |
42 |
Correct |
32 ms |
70956 KB |
Output is correct |
43 |
Execution timed out |
1058 ms |
99892 KB |
Time limit exceeded |
44 |
Correct |
987 ms |
71980 KB |
Output is correct |
45 |
Execution timed out |
1056 ms |
99892 KB |
Time limit exceeded |
46 |
Execution timed out |
1100 ms |
99864 KB |
Time limit exceeded |
47 |
Execution timed out |
1046 ms |
99908 KB |
Time limit exceeded |
48 |
Execution timed out |
1012 ms |
99924 KB |
Time limit exceeded |
49 |
Execution timed out |
1008 ms |
99956 KB |
Time limit exceeded |
50 |
Execution timed out |
1039 ms |
99916 KB |
Time limit exceeded |
51 |
Execution timed out |
1012 ms |
100044 KB |
Time limit exceeded |
52 |
Execution timed out |
1045 ms |
99900 KB |
Time limit exceeded |
53 |
Execution timed out |
1037 ms |
99920 KB |
Time limit exceeded |
54 |
Execution timed out |
1057 ms |
99952 KB |
Time limit exceeded |
55 |
Execution timed out |
1072 ms |
99916 KB |
Time limit exceeded |
56 |
Execution timed out |
1040 ms |
99920 KB |
Time limit exceeded |
57 |
Execution timed out |
1040 ms |
99916 KB |
Time limit exceeded |
58 |
Execution timed out |
1060 ms |
99920 KB |
Time limit exceeded |
59 |
Execution timed out |
1043 ms |
99920 KB |
Time limit exceeded |
60 |
Execution timed out |
1030 ms |
99920 KB |
Time limit exceeded |
61 |
Execution timed out |
1050 ms |
99936 KB |
Time limit exceeded |
62 |
Execution timed out |
1060 ms |
99920 KB |
Time limit exceeded |
63 |
Execution timed out |
1070 ms |
99856 KB |
Time limit exceeded |
64 |
Execution timed out |
1053 ms |
99920 KB |
Time limit exceeded |
65 |
Execution timed out |
1051 ms |
99920 KB |
Time limit exceeded |
66 |
Execution timed out |
1024 ms |
99920 KB |
Time limit exceeded |
67 |
Execution timed out |
1053 ms |
99920 KB |
Time limit exceeded |
68 |
Execution timed out |
1051 ms |
99924 KB |
Time limit exceeded |
69 |
Execution timed out |
1096 ms |
99852 KB |
Time limit exceeded |
70 |
Execution timed out |
1051 ms |
90512 KB |
Time limit exceeded |
71 |
Execution timed out |
1025 ms |
99920 KB |
Time limit exceeded |
72 |
Execution timed out |
1093 ms |
99920 KB |
Time limit exceeded |
73 |
Execution timed out |
1018 ms |
99944 KB |
Time limit exceeded |
74 |
Execution timed out |
1046 ms |
99916 KB |
Time limit exceeded |
75 |
Execution timed out |
1049 ms |
99832 KB |
Time limit exceeded |
76 |
Execution timed out |
1044 ms |
99844 KB |
Time limit exceeded |
77 |
Execution timed out |
1078 ms |
99920 KB |
Time limit exceeded |
78 |
Execution timed out |
1043 ms |
99932 KB |
Time limit exceeded |
79 |
Execution timed out |
1056 ms |
99916 KB |
Time limit exceeded |
80 |
Execution timed out |
1045 ms |
99920 KB |
Time limit exceeded |
81 |
Execution timed out |
1106 ms |
99884 KB |
Time limit exceeded |
82 |
Execution timed out |
1051 ms |
99916 KB |
Time limit exceeded |
83 |
Execution timed out |
1060 ms |
99928 KB |
Time limit exceeded |
84 |
Execution timed out |
1036 ms |
99912 KB |
Time limit exceeded |
85 |
Execution timed out |
1018 ms |
99916 KB |
Time limit exceeded |
86 |
Execution timed out |
1049 ms |
99916 KB |
Time limit exceeded |
87 |
Execution timed out |
1010 ms |
99924 KB |
Time limit exceeded |
88 |
Execution timed out |
1052 ms |
99916 KB |
Time limit exceeded |
89 |
Execution timed out |
1057 ms |
99844 KB |
Time limit exceeded |
90 |
Execution timed out |
1045 ms |
90556 KB |
Time limit exceeded |
91 |
Execution timed out |
1010 ms |
99932 KB |
Time limit exceeded |
92 |
Execution timed out |
1037 ms |
99896 KB |
Time limit exceeded |
93 |
Execution timed out |
1055 ms |
100032 KB |
Time limit exceeded |
94 |
Execution timed out |
1056 ms |
99912 KB |
Time limit exceeded |
95 |
Execution timed out |
1037 ms |
99920 KB |
Time limit exceeded |
96 |
Execution timed out |
1054 ms |
99948 KB |
Time limit exceeded |
97 |
Execution timed out |
1050 ms |
99908 KB |
Time limit exceeded |
98 |
Execution timed out |
1068 ms |
99860 KB |
Time limit exceeded |
99 |
Execution timed out |
1061 ms |
99932 KB |
Time limit exceeded |
100 |
Execution timed out |
1038 ms |
99976 KB |
Time limit exceeded |