제출 #1205697

#제출 시각아이디문제언어결과실행 시간메모리
120569712345678과수원 (NOI14_orchard)C++20
17 / 25
147 ms6348 KiB
#include <bits/stdc++.h> using namespace std; const int nx=155, mx=5e3+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; }
#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...