Submission #516348

#TimeUsernameProblemLanguageResultExecution timeMemory
516348JomnoiOrchard (NOI14_orchard)C++17
25 / 25
332 ms49172 KiB
#include <bits/stdc++.h> #define DEBUG 0 using namespace std; const int INF = 1e9 + 7; vector <vector <int>> a; vector <int> dp; int get(int x1, int x2, int y1, int y2) { return a[x2][y2] - a[x1 - 1][y2] - a[x2][y1 - 1] + a[x1 - 1][y1 - 1]; } int main() { int n, m; scanf(" %d %d", &n, &m); a.resize(n + 10, vector <int> (m + 10)); dp.resize(m + 10); int sum = 0; 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 { sum++; a[i][j] = -1; } a[i][j] += a[i - 1][j] + a[i][j - 1] - a[i - 1][j - 1]; } } int ans = INF; dp[m + 1] = INF; for(int i = 1; i <= n; i++) { for(int j = i; j <= n; j++) { for(int k = m; k >= 1; k--) { dp[k] = min(dp[k + 1], get(i, j, 1, k)); } if(DEBUG) { cout << "Debugging : " << i << " " << j << endl; for(int k = 1; k <= m; k++) { cout << dp[k] << " "; } cout << endl; } for(int k = 1; k <= m; k++) { ans = min(ans, sum + dp[k] - get(i, j, 1, k - 1)); } } } cout << ans; return 0; }

Compilation message (stderr)

orchard.cpp: In function 'int main()':
orchard.cpp:16:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 |     scanf(" %d %d", &n, &m);
      |     ~~~~~^~~~~~~~~~~~~~~~~~
orchard.cpp:23:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   23 |             scanf(" %d", &a[i][j]);
      |             ~~~~~^~~~~~~~~~~~~~~~~
#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...