#include<iostream>
using namespace std;
int n,m;
char mat[2505][2505];
int sump[2505][2505];
int mars[2505][2505];
bool verif(int cntx, int cnty)
{
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
mars[i][j]=0;
for(int i=1;i+cntx-1<=n;i++)
{
for(int j=1;j+cnty-1<=m;j++)
{
if(sump[i+cntx-1][j+cnty-1] - sump[i+cntx-1][j-1] - sump[i-1][j+cnty-1] + sump[i-1][j-1] == cntx*cnty)///toate is 1
{
mars[i][j]++;
mars[i][j+cnty]--;
mars[i+cntx][j]--;
mars[i+cntx][j+cnty]++;
}
}
}
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
mars[i][j] += mars[i-1][j] + mars[i][j-1] - mars[i-1][j-1];
if(mars[i][j]==0 && mat[i][j]=='1')
return 0;
}
}
return 1;
}
signed main()
{
cin>>n>>m;
int minx=n,miny=m;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
cin>>mat[i][j];
sump[i][j] = sump[i-1][j] + sump[i][j-1] - sump[i-1][j-1];
if(mat[i][j]=='1')
sump[i][j]++;
}
}
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
if(mat[i][j]=='1' && (j==m || mat[i][j+1]=='0'))
{
int cnt=0;
for(int u=j;u>0;u--)
{
if(mat[i][u]=='0')
break;
cnt++;
}
miny = min(miny, cnt);
}
}
}
for(int i=1;i<=m;i++)
{
for(int j=1;j<=n;j++)
{
if(mat[j][i]=='1' && (j==n || mat[j+1][i]=='0'))
{
int cnt=0;
for(int u=j;u>0;u--)
{
if(mat[u][i]=='0')
break;
cnt++;
}
minx = min(minx, cnt);
}
}
}
minx=n;miny=m;
int poz=0, mxm=0;
for(int i=minx;i>0;i--)
{
if(i*miny <= mxm)
break;
while(poz+1<=miny && verif(i,poz+1))
{
poz++;
}
mxm = max(mxm, i*poz);
}
cout<<mxm;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
4700 KB |
Output is correct |
3 |
Correct |
69 ms |
40996 KB |
Output is correct |
4 |
Correct |
72 ms |
40996 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
4700 KB |
Output is correct |
9 |
Correct |
1 ms |
4696 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
4700 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 |
4700 KB |
Output is correct |
17 |
Correct |
1 ms |
4700 KB |
Output is correct |
18 |
Correct |
1 ms |
4700 KB |
Output is correct |
19 |
Correct |
2 ms |
4956 KB |
Output is correct |
20 |
Correct |
2 ms |
5208 KB |
Output is correct |
21 |
Correct |
1 ms |
4696 KB |
Output is correct |
22 |
Correct |
2 ms |
5204 KB |
Output is correct |
23 |
Correct |
2 ms |
4956 KB |
Output is correct |
24 |
Correct |
2 ms |
4956 KB |
Output is correct |
25 |
Correct |
4 ms |
5068 KB |
Output is correct |
26 |
Correct |
3 ms |
4956 KB |
Output is correct |
27 |
Correct |
34 ms |
10040 KB |
Output is correct |
28 |
Correct |
25 ms |
10328 KB |
Output is correct |
29 |
Correct |
92 ms |
10764 KB |
Output is correct |
30 |
Correct |
165 ms |
11100 KB |
Output is correct |
31 |
Correct |
107 ms |
10668 KB |
Output is correct |
32 |
Correct |
87 ms |
10976 KB |
Output is correct |
33 |
Correct |
156 ms |
13416 KB |
Output is correct |
34 |
Correct |
24 ms |
10504 KB |
Output is correct |
35 |
Correct |
166 ms |
13416 KB |
Output is correct |
36 |
Correct |
117 ms |
13416 KB |
Output is correct |
37 |
Correct |
1 ms |
4712 KB |
Output is correct |
38 |
Execution timed out |
1026 ms |
55472 KB |
Time limit exceeded |
39 |
Correct |
1 ms |
4700 KB |
Output is correct |
40 |
Execution timed out |
1092 ms |
22184 KB |
Time limit exceeded |
41 |
Correct |
1 ms |
4696 KB |
Output is correct |
42 |
Correct |
5 ms |
4952 KB |
Output is correct |
43 |
Execution timed out |
1060 ms |
55468 KB |
Time limit exceeded |
44 |
Correct |
227 ms |
13400 KB |
Output is correct |
45 |
Execution timed out |
1098 ms |
55596 KB |
Time limit exceeded |
46 |
Execution timed out |
1057 ms |
55380 KB |
Time limit exceeded |
47 |
Execution timed out |
1070 ms |
55528 KB |
Time limit exceeded |
48 |
Execution timed out |
1077 ms |
55460 KB |
Time limit exceeded |
49 |
Execution timed out |
1066 ms |
55380 KB |
Time limit exceeded |
50 |
Execution timed out |
1050 ms |
55376 KB |
Time limit exceeded |
51 |
Execution timed out |
1060 ms |
55380 KB |
Time limit exceeded |
52 |
Execution timed out |
1046 ms |
55532 KB |
Time limit exceeded |
53 |
Execution timed out |
1059 ms |
55396 KB |
Time limit exceeded |
54 |
Execution timed out |
1063 ms |
55496 KB |
Time limit exceeded |
55 |
Execution timed out |
1027 ms |
55636 KB |
Time limit exceeded |
56 |
Execution timed out |
1059 ms |
55468 KB |
Time limit exceeded |
57 |
Execution timed out |
1065 ms |
55464 KB |
Time limit exceeded |
58 |
Execution timed out |
1039 ms |
55484 KB |
Time limit exceeded |
59 |
Execution timed out |
1027 ms |
55528 KB |
Time limit exceeded |
60 |
Execution timed out |
1072 ms |
55480 KB |
Time limit exceeded |
61 |
Execution timed out |
1034 ms |
55972 KB |
Time limit exceeded |
62 |
Execution timed out |
1036 ms |
55376 KB |
Time limit exceeded |
63 |
Execution timed out |
1070 ms |
55476 KB |
Time limit exceeded |
64 |
Execution timed out |
1033 ms |
55376 KB |
Time limit exceeded |
65 |
Execution timed out |
1030 ms |
55376 KB |
Time limit exceeded |
66 |
Execution timed out |
1064 ms |
55636 KB |
Time limit exceeded |
67 |
Execution timed out |
1033 ms |
55464 KB |
Time limit exceeded |
68 |
Execution timed out |
1052 ms |
55476 KB |
Time limit exceeded |
69 |
Execution timed out |
1050 ms |
55492 KB |
Time limit exceeded |
70 |
Execution timed out |
1087 ms |
47292 KB |
Time limit exceeded |
71 |
Execution timed out |
1041 ms |
55544 KB |
Time limit exceeded |
72 |
Execution timed out |
1061 ms |
55476 KB |
Time limit exceeded |
73 |
Execution timed out |
1029 ms |
55456 KB |
Time limit exceeded |
74 |
Execution timed out |
1069 ms |
55472 KB |
Time limit exceeded |
75 |
Execution timed out |
1049 ms |
55480 KB |
Time limit exceeded |
76 |
Execution timed out |
1022 ms |
55472 KB |
Time limit exceeded |
77 |
Execution timed out |
1028 ms |
55532 KB |
Time limit exceeded |
78 |
Execution timed out |
1046 ms |
55484 KB |
Time limit exceeded |
79 |
Execution timed out |
1027 ms |
55376 KB |
Time limit exceeded |
80 |
Execution timed out |
1064 ms |
55464 KB |
Time limit exceeded |
81 |
Execution timed out |
1048 ms |
55576 KB |
Time limit exceeded |
82 |
Execution timed out |
1092 ms |
55464 KB |
Time limit exceeded |
83 |
Execution timed out |
1049 ms |
55532 KB |
Time limit exceeded |
84 |
Execution timed out |
1068 ms |
55504 KB |
Time limit exceeded |
85 |
Execution timed out |
1038 ms |
55500 KB |
Time limit exceeded |
86 |
Execution timed out |
1063 ms |
55484 KB |
Time limit exceeded |
87 |
Execution timed out |
1070 ms |
55380 KB |
Time limit exceeded |
88 |
Execution timed out |
1053 ms |
55556 KB |
Time limit exceeded |
89 |
Execution timed out |
1047 ms |
55816 KB |
Time limit exceeded |
90 |
Execution timed out |
1040 ms |
47272 KB |
Time limit exceeded |
91 |
Execution timed out |
1040 ms |
55484 KB |
Time limit exceeded |
92 |
Execution timed out |
1050 ms |
55512 KB |
Time limit exceeded |
93 |
Execution timed out |
1054 ms |
55612 KB |
Time limit exceeded |
94 |
Execution timed out |
1043 ms |
55720 KB |
Time limit exceeded |
95 |
Execution timed out |
1033 ms |
55472 KB |
Time limit exceeded |
96 |
Execution timed out |
1053 ms |
55420 KB |
Time limit exceeded |
97 |
Execution timed out |
1046 ms |
55468 KB |
Time limit exceeded |
98 |
Execution timed out |
1046 ms |
55464 KB |
Time limit exceeded |
99 |
Execution timed out |
1069 ms |
55468 KB |
Time limit exceeded |
100 |
Execution timed out |
1016 ms |
55612 KB |
Time limit exceeded |