Submission #29462

#TimeUsernameProblemLanguageResultExecution timeMemory
29462samir_droubiOrchard (NOI14_orchard)C++14
25 / 25
196 ms16768 KiB
#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)

orchard.cpp: In function 'void solve1()':
orchard.cpp:14:33: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d",&a[i][j]);
                                 ^
orchard.cpp: In function 'void solve2()':
orchard.cpp:44:33: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d",&b[i][j]);
                                 ^
orchard.cpp: In function 'int main()':
orchard.cpp:68:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d",&n,&m);
                        ^
#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...