Submission #5694

#TimeUsernameProblemLanguageResultExecution timeMemory
5694cki86201Orchard (NOI14_orchard)C++98
25 / 25
588 ms9056 KiB
#include<stdio.h> #include<algorithm> #include<vector> using namespace std; vector<vector <int> > p; int n, m, ans = ~0u>>1; inline int get(int x1,int y1,int x2,int y2){return p[x2][y2] - p[x2][y1-1] - p[x1-1][y2] + p[x1-1][y1-1];} int main() { scanf("%d%d",&n,&m); p.resize(n+1);p[0].resize(m+1); int i, j; for(i=1;i<=n;i++){ p[i].resize(m+1); for(j=1;j<=m;j++)scanf("%d",&p[i][j]); } for(i=1;i<=n;i++)for(j=1;j<=m;j++)p[i][j] += p[i][j-1] + p[i-1][j] - p[i-1][j-1]; for(i=1;i<=n;i++){ for(j=i;j<=n;j++){ int now = 0; for(int k=1;k<=m;k++){ ans = std::min(ans, (j-i+1) * (k-now) - 2 * get(i, now+1, j, k) + p[n][m]); if(get(i, now+1, j, k)*2 < (j-i+1) * (k-now))now = k; } } } printf("%d",ans); return 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...