# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
29462 | samir_droubi | Orchard (NOI14_orchard) | C++14 | 196 ms | 16768 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
int b[3][1000005];
int a[155][5005];
int n,m;
void solve1()
{
int c=0;
int ans=(1e9);
for(int i=1;i<=n;++i)
for(int j=1;j<=m;++j)
{
scanf("%d",&a[i][j]);
if(a[i][j]==0) a[i][j]=1 ;
else a[i][j]=-1,++c;
a[i][j]+=a[i-1][j];
}
for(int i=1;i<=n;++i)
for(int j=i;j<=n;++j)
{
int mx=0;
int sm=0;
for(int k=1;k<=m;++k)
{
sm+=a[j][k]-a[i-1][k];
ans=min(ans,sm-mx);
mx=max(mx,sm);
}
}
printf("%d\n",c+ans);
}
void solve2()
{
int c=0;
int ans=(1e9);
for(int i=1;i<=n;++i)
for(int j=1;j<=m;++j)
{
scanf("%d",&b[i][j]);
if(b[i][j]==0) b[i][j]=1 ;
else b[i][j]=-1,++c;
b[i][j]+=b[i-1][j];
}
for(int i=1;i<=n;++i)
for(int j=i;j<=n;++j)
{
int mx=0;
int sm=0;
for(int k=1;k<=m;++k)
{
sm+=b[j][k]-b[i-1][k];
ans=min(ans,sm-mx);
mx=max(mx,sm);
}
}
printf("%d\n",c+ans);
}
int main()
{
scanf("%d%d",&n,&m);
if(m<=5000)
solve1();
else
solve2();
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |