Submission #1205698

#TimeUsernameProblemLanguageResultExecution timeMemory
120569812345678Orchard (NOI14_orchard)C++20
16 / 25
46 ms12104 KiB
#include <bits/stdc++.h>

using namespace std;

const int nx=3, mx=1e6+5;

int n, m, mp[nx][mx], qs[nx][mx], pref[mx], res=INT_MAX, tot;

int main()
{
    cin.tie(NULL)->sync_with_stdio(false);
    cin>>n>>m;
    for (int i=1; i<=n; i++) for (int j=1; j<=m; j++) cin>>mp[i][j], tot+=mp[i][j];
    for (int j=1; j<=m; j++) for (int i=1; i<=n; i++) qs[i][j]=qs[i-1][j]+(mp[i][j]?-1:1);
    for (int i=1; i<=n; i++)
    {
        for (int j=i; j<=n; j++)
        {
            int mn=0;
            for (int k=1; k<=m; k++)
            {
                pref[k]=pref[k-1]+qs[j][k]-qs[i-1][k];
                //cout<<"debug "<<i<<' '<<j<<' '<<k<<' '<<pref[k]<<'\n';
                mn=max(mn, pref[k]);
                res=min(res, pref[k]-mn+tot);
            }
        }
    }
    cout<<res;
}

/*
5 7
0 0 1 0 0 1 0
0 1 1 1 1 1 0
0 1 1 0 0 1 0
0 1 1 1 1 1 0
0 0 1 0 0 1 0
*/
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...