Submission #265286

#TimeUsernameProblemLanguageResultExecution timeMemory
265286T0p_Orchard (NOI14_orchard)C++14
25 / 25
427 ms25824 KiB
#include<bits/stdc++.h> using namespace std; int dp[155][155][2]; int main() { int n, m; scanf(" %d %d",&n,&m); int arr[n+5][m+5]; memset(arr, 0, sizeof arr); for(int i=1 ; i<=n ; i++) for(int j=1 ; j<=m ; j++) { scanf(" %d",&arr[i][j]); arr[i][j] += arr[i-1][j] + arr[i][j-1] - arr[i-1][j-1]; } int ans = 1e9; for(int sz=1 ; sz<=n ; sz++) for(int i=1 ; i<=n ; i++) { int j = i+sz-1; if(j > n) break ; for(int k=1 ; k<=m ; k++) { dp[i][j][k%2] = min(dp[i][j][(k-1)%2], arr[j][k-1] - arr[i-1][k-1]) + sz - arr[j][k] + arr[j][k-1] + arr[i-1][k] - arr[i-1][k-1]; ans = min(ans, dp[i][j][k%2] + arr[j][m] - arr[j][k] + arr[i-1][k] + arr[n][m] - arr[j][m]); } } printf("%d\n",ans); return 0; } // dp[i][j][k] -> row ith to row jth, col 1st to col kth and end the second area on col kth /* 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 */

Compilation message (stderr)

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