Submission #47344

# Submission time Handle Problem Language Result Execution time Memory
47344 2018-05-01T06:48:58 Z dqhungdl Orchard (NOI14_orchard) C++17
0 / 25
363 ms 8144 KB
#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[i-1]+c1[n]-c0[i-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 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 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 488 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 516 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 1492 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 363 ms 8144 KB Output isn't correct
2 Halted 0 ms 0 KB -