//#pragma GCC optimize("O3,unroll-loops")
//#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#include <bits/stdc++.h>
#define endl "\n"
#define F first
#define S second
#define pb push_back
//#define int long long
#define in insert
#define mid (l+r)/2
#define in insert
using namespace std;
const int N=2505;
char b[N][N];
int n,m,pref[N][N];
//set<pair<int,int>> adj[N][N];
void init(){
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
pref[i][j]=pref[i-1][j]+pref[i][j-1]-pref[i-1][j-1]+bool(b[i][j]=='1');
}
}
return ;
}
int query(int x , int y , int x1 , int y1){
return pref[x1][y1]-pref[x1][y-1]-pref[x-1][y1]+pref[x-1][y-1];
}
int32_t main(){
ios::sync_with_stdio(false);cin.tie(nullptr);
cin>>n>>m;
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++) cin>>b[i][j];
init();
if(n==1){
int mx=m;
for(int i=1;i<=m;i++){
if(b[1][i]=='1'){
int cnt=1;
while(i+1<=m && b[1][i+1]==b[1][i]){
++i;
++cnt;
}
mx=min(mx,cnt);
++i;
}
}
cout<<mx;
}
else if(m==1){
int mx=n;
for(int i=1;i<=n;i++){
if(b[i][1]=='1'){
int cnt=1;
while(i+1<=n && b[i+1][1]==b[i][1]){
++i;
++cnt;
}
mx=min(mx,cnt);
++i;
}
}
cout<<mx;
}
/*else{
int mx=0,all=0;
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++) if(b[i][j]=='1') ++all;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
if(b[i][j]=='0') continue ;
for(int i1=1;i1<=i;i1++){
for(int j1=1;j1<=j;j1++){
for(int i2=i;i2<=n;i2++){
for(int j2=j;j2<=m;j2++){
if(b[i1][j1]=='1' && b[i2][j2]=='1' && query(i1,j1,i2,j2)==(i2-i1+1)*(j2-j1+1)){
adj[i2-i1+1][j2-j1+1].in({i,j});
}
}
}
}
}
}
}
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
if((int)adj[i][j].size()==all) mx=max(mx,i*j);
}
}
cout<<mx;
}*/
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
760 KB |
Output is correct |
3 |
Correct |
11 ms |
16476 KB |
Output is correct |
4 |
Correct |
12 ms |
16472 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Incorrect |
1 ms |
480 KB |
Output isn't correct |
8 |
Incorrect |
1 ms |
604 KB |
Output isn't correct |
9 |
Incorrect |
1 ms |
488 KB |
Output isn't correct |
10 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
11 |
Incorrect |
1 ms |
604 KB |
Output isn't correct |
12 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
13 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
14 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
15 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
16 |
Incorrect |
1 ms |
480 KB |
Output isn't correct |
17 |
Incorrect |
1 ms |
860 KB |
Output isn't correct |
18 |
Incorrect |
1 ms |
860 KB |
Output isn't correct |
19 |
Incorrect |
2 ms |
1116 KB |
Output isn't correct |
20 |
Incorrect |
1 ms |
1280 KB |
Output isn't correct |
21 |
Incorrect |
1 ms |
604 KB |
Output isn't correct |
22 |
Incorrect |
1 ms |
860 KB |
Output isn't correct |
23 |
Incorrect |
2 ms |
1116 KB |
Output isn't correct |
24 |
Incorrect |
1 ms |
860 KB |
Output isn't correct |
25 |
Incorrect |
2 ms |
1120 KB |
Output isn't correct |
26 |
Incorrect |
1 ms |
1056 KB |
Output isn't correct |
27 |
Incorrect |
4 ms |
2652 KB |
Output isn't correct |
28 |
Incorrect |
4 ms |
2908 KB |
Output isn't correct |
29 |
Incorrect |
4 ms |
3420 KB |
Output isn't correct |
30 |
Incorrect |
5 ms |
4188 KB |
Output isn't correct |
31 |
Incorrect |
4 ms |
3300 KB |
Output isn't correct |
32 |
Incorrect |
7 ms |
3832 KB |
Output isn't correct |
33 |
Incorrect |
6 ms |
4332 KB |
Output isn't correct |
34 |
Incorrect |
5 ms |
3164 KB |
Output isn't correct |
35 |
Incorrect |
6 ms |
4188 KB |
Output isn't correct |
36 |
Incorrect |
7 ms |
4444 KB |
Output isn't correct |
37 |
Incorrect |
1 ms |
604 KB |
Output isn't correct |
38 |
Incorrect |
84 ms |
34296 KB |
Output isn't correct |
39 |
Incorrect |
1 ms |
604 KB |
Output isn't correct |
40 |
Incorrect |
15 ms |
9612 KB |
Output isn't correct |
41 |
Incorrect |
1 ms |
760 KB |
Output isn't correct |
42 |
Incorrect |
2 ms |
1116 KB |
Output isn't correct |
43 |
Incorrect |
79 ms |
34376 KB |
Output isn't correct |
44 |
Incorrect |
5 ms |
4176 KB |
Output isn't correct |
45 |
Incorrect |
89 ms |
34376 KB |
Output isn't correct |
46 |
Incorrect |
91 ms |
35912 KB |
Output isn't correct |
47 |
Incorrect |
92 ms |
34376 KB |
Output isn't correct |
48 |
Incorrect |
78 ms |
34376 KB |
Output isn't correct |
49 |
Incorrect |
75 ms |
34324 KB |
Output isn't correct |
50 |
Incorrect |
89 ms |
34376 KB |
Output isn't correct |
51 |
Incorrect |
77 ms |
34396 KB |
Output isn't correct |
52 |
Incorrect |
71 ms |
34376 KB |
Output isn't correct |
53 |
Incorrect |
89 ms |
34312 KB |
Output isn't correct |
54 |
Incorrect |
76 ms |
35856 KB |
Output isn't correct |
55 |
Incorrect |
78 ms |
34316 KB |
Output isn't correct |
56 |
Incorrect |
94 ms |
34376 KB |
Output isn't correct |
57 |
Incorrect |
90 ms |
34376 KB |
Output isn't correct |
58 |
Incorrect |
73 ms |
34364 KB |
Output isn't correct |
59 |
Incorrect |
74 ms |
34376 KB |
Output isn't correct |
60 |
Incorrect |
81 ms |
34376 KB |
Output isn't correct |
61 |
Incorrect |
91 ms |
34320 KB |
Output isn't correct |
62 |
Incorrect |
81 ms |
34268 KB |
Output isn't correct |
63 |
Incorrect |
78 ms |
34256 KB |
Output isn't correct |
64 |
Incorrect |
81 ms |
34348 KB |
Output isn't correct |
65 |
Incorrect |
90 ms |
34232 KB |
Output isn't correct |
66 |
Incorrect |
74 ms |
34384 KB |
Output isn't correct |
67 |
Incorrect |
89 ms |
35840 KB |
Output isn't correct |
68 |
Incorrect |
73 ms |
34376 KB |
Output isn't correct |
69 |
Incorrect |
76 ms |
35916 KB |
Output isn't correct |
70 |
Incorrect |
51 ms |
27224 KB |
Output isn't correct |
71 |
Incorrect |
81 ms |
34400 KB |
Output isn't correct |
72 |
Incorrect |
95 ms |
35912 KB |
Output isn't correct |
73 |
Incorrect |
93 ms |
34324 KB |
Output isn't correct |
74 |
Incorrect |
75 ms |
34312 KB |
Output isn't correct |
75 |
Incorrect |
99 ms |
34360 KB |
Output isn't correct |
76 |
Incorrect |
91 ms |
34388 KB |
Output isn't correct |
77 |
Incorrect |
74 ms |
34376 KB |
Output isn't correct |
78 |
Incorrect |
96 ms |
35820 KB |
Output isn't correct |
79 |
Incorrect |
93 ms |
35872 KB |
Output isn't correct |
80 |
Incorrect |
77 ms |
35904 KB |
Output isn't correct |
81 |
Incorrect |
80 ms |
35808 KB |
Output isn't correct |
82 |
Incorrect |
77 ms |
34340 KB |
Output isn't correct |
83 |
Incorrect |
73 ms |
34296 KB |
Output isn't correct |
84 |
Incorrect |
86 ms |
35764 KB |
Output isn't correct |
85 |
Incorrect |
92 ms |
34412 KB |
Output isn't correct |
86 |
Incorrect |
96 ms |
34372 KB |
Output isn't correct |
87 |
Incorrect |
96 ms |
34376 KB |
Output isn't correct |
88 |
Incorrect |
84 ms |
35912 KB |
Output isn't correct |
89 |
Incorrect |
95 ms |
34296 KB |
Output isn't correct |
90 |
Incorrect |
62 ms |
27240 KB |
Output isn't correct |
91 |
Incorrect |
80 ms |
35920 KB |
Output isn't correct |
92 |
Incorrect |
79 ms |
35884 KB |
Output isn't correct |
93 |
Incorrect |
76 ms |
34376 KB |
Output isn't correct |
94 |
Incorrect |
80 ms |
34336 KB |
Output isn't correct |
95 |
Incorrect |
94 ms |
34380 KB |
Output isn't correct |
96 |
Incorrect |
85 ms |
35916 KB |
Output isn't correct |
97 |
Incorrect |
102 ms |
35896 KB |
Output isn't correct |
98 |
Incorrect |
91 ms |
34396 KB |
Output isn't correct |
99 |
Incorrect |
92 ms |
35836 KB |
Output isn't correct |
100 |
Incorrect |
102 ms |
35752 KB |
Output isn't correct |