#include <bits/stdc++.h>
using namespace std;
int m,n,res=1e9,c0[1000005],c1[1000005],s[2][155][5005];
int Sum(int t,int u1,int v1,int u2,int v2)
{
return s[t][u2][v2]-s[t][u1-1][v2]-s[t][u2][v1-1]+s[t][u1-1][v1-1];
}
void Sub1()
{
int x;
for(int i=1;i<=m;i++)
for(int j=1;j<=n;j++)
{
cin>>x;
s[0][i][j]+=s[0][i-1][j]+s[0][i][j-1]-s[0][i-1][j-1]+(x==0);
s[1][i][j]+=s[1][i-1][j]+s[1][i][j-1]-s[1][i-1][j-1]+(x==1);
}
for(int i=1;i<=m;i++)
for(int j=i;j<=m;j++)
{
int add=Sum(1,1,1,i-1,n)+Sum(1,j+1,1,m,n);
for(int t=1;t<=n;t++)
{
c0[t]=c0[t-1]+Sum(0,i,t,j,t);
c1[t]=c1[t-1]+Sum(1,i,t,j,t);
}
int minn=1e9;
for(int t=n;t>=1;t--)
{
minn=min(minn,c0[t]-c1[t]);
res=min(res,c1[t-1]+c1[n]-c0[t-1]+minn+add);
}
}
cout<<res;
}
int main()
{
ios_base::sync_with_stdio(false);
//freopen("TEST.INP","r",stdin);
cin>>m>>n;
if(m<=150&&n<=5000)
Sub1();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
488 KB |
Output is correct |
3 |
Correct |
2 ms |
488 KB |
Output is correct |
4 |
Correct |
2 ms |
488 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
488 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
632 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
656 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
1500 KB |
Output is correct |
2 |
Correct |
13 ms |
2140 KB |
Output is correct |
3 |
Correct |
13 ms |
2140 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
330 ms |
6700 KB |
Output is correct |
2 |
Correct |
343 ms |
8152 KB |
Output is correct |
3 |
Correct |
334 ms |
9636 KB |
Output is correct |