Submission #962583

#TimeUsernameProblemLanguageResultExecution timeMemory
962583starchanRaisins (IOI09_raisins)C++17
100 / 100
123 ms57716 KiB
#include<bits/stdc++.h> using namespace std; #define int long long #define in pair<int, int> #define f first #define s second #define pb push_back #define pob pop_back #define INF (int)1e17 #define fast() ios_base::sync_with_stdio(false); cin.tie(NULL) const int MX = 52; int a[MX][MX]; int dp[MX][MX][MX][MX]; int C(int lx, int rx, int ly, int ry) { return a[rx][ry]-a[rx][ly-1]-a[lx-1][ry]+a[lx-1][ly-1]; } int solve(int lx, int rx, int ly, int ry) { if(dp[lx][rx][ly][ry] != -1) return dp[lx][rx][ly][ry]; int val = INF; for(int mx = lx; mx < rx; mx++) val = min(val, solve(lx, mx, ly, ry)+solve(mx+1, rx, ly, ry)); for(int my = ly; my < ry; my++) val = min(val, solve(lx, rx, ly, my)+solve(lx, rx, my+1, ry)); if(val == INF) return dp[lx][rx][ly][ry] = 0; else return dp[lx][rx][ly][ry] = C(lx, rx, ly, ry)+val; } signed main() { fast(); int n, m; cin >> n >> m; for(auto &i: dp) for(auto &j: i) for(auto &k: j) for(auto &l: k) l = -1; for(int i = 1; i <= n; i++) { for(int j = 1; j <= m; j++) cin >> a[i][j]; } for(int i = 1; i <= n; i++) { for(int j = 1; j <= m; j++) a[i][j]+=a[i][j-1]; } for(int i = 1; i <= n; i++) { for(int j = 1; j <= m; j++) a[i][j]+=a[i-1][j]; } cout << solve(1, n, 1, m) << "\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...