#include <bits/stdc++.h>
#define boost ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
const int N = 2505;
const int inf = 1e9;
const int mod=1e9+7;
struct edge{
int pos,val,t;
};
int dp[N][N];
string c[N];
int dp1[N][N];
vector<pair<int,int> >v[202502];
int n,m;
int ch(int x){
int ok=0;
for(int l=0;l<v[x].size();l++){
int cnt=0;
int i=v[x][l].first;
int j=v[x][l].second;
for(int y=1;y+i-1<=n;y++){
for(int x=1;x+j-1<=m;x++){
int x1=x+(j-1);
int y1=y+(i-1);
int cnt=dp[y1][x1]-dp[y1][x - 1]-dp[y - 1][x1]+dp[y - 1][x - 1];
if(cnt==i*j){
dp1[y][x]++;
dp1[y1+1][x]--;
dp1[y][x1+1]--;
dp1[y1+1][x1+1]++;
}
}
}
int cnt1=0;
for(int y=1;y<=n;y++){
for(int x=1;x<=m;x++){
dp1[y][x]+=dp1[y-1][x]+dp1[y][x-1]-dp1[y-1][x-1];
if(dp1[y][x]>0){
cnt1++;
}
}
}
if(cnt1==dp[n][m]){
ok=1;
}
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
dp1[i][j]=0;
}
}
if(ok==1){
break;
}
}
return ok;
}
signed main(){
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
boost
cin>>n>>m;
for(int i=1;i<=n;i++){
cin>>c[i];
for(int j=0;j<m;j++){
int x=0;
if(c[i][j]=='1'){
x=1;
}
dp[i][j+1]=dp[i-1][j+1]+dp[i][j]-dp[i-1][j]+x;
}
}
for(int i=1;i<=n*m;i++){
for(int j=1;j<=sqrt(i);j++){
if(i%j==0){
v[i].push_back({i/j,j});
v[i].push_back({j,i/j});
}
}
}
int ans=0;
int j=2;
for(int i=n*m;i>=max(n*m-100,1);i--){
if(ch(i)==1){
cout<<i;
return 0;
}
}
for(int i=min(n*m,100);i>=1;i--){
if(ch(i)==1){
ans=i;
}
}
int st=101;
int end=n*m-101;
for(int i=1;i<=100;i++){
int x=rand()%(end-st+1)+st;
if(ch(x)==1){
ans=max(ans,x);
}
}
cout<<ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |