Submission #507596

#TimeUsernameProblemLanguageResultExecution timeMemory
507596tabrRaisins (IOI09_raisins)C++17
100 / 100
189 ms31996 KiB
#include <bits/stdc++.h> using namespace std; #ifdef tabr #include "library/debug.cpp" #else #define debug(...) #endif int main() { ios::sync_with_stdio(false); cin.tie(0); int h, w; cin >> h >> w; vector<vector<int>> a(h, vector<int>(w)); for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { cin >> a[i][j]; } } vector<vector<int>> pref(h + 1, vector<int>(w + 1)); for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { pref[i + 1][j + 1] = pref[i + 1][j] + pref[i][j + 1] - pref[i][j] + a[i][j]; } } const int inf = (int) 1e9; vector dp(h, vector(h + 1, vector(w, vector<int>(w + 1, inf)))); for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { dp[i][i + 1][j][j + 1] = 0; } } for (int i1 = h - 1; i1 >= 0; i1--) { for (int i2 = i1 + 1; i2 <= h; i2++) { for (int j1 = w - 1; j1 >= 0; j1--) { for (int j2 = j1 + 1; j2 <= w; j2++) { int sum = pref[i2][j2] - pref[i1][j2] - pref[i2][j1] + pref[i1][j1]; for (int i = i1 + 1; i < i2; i++) { dp[i1][i2][j1][j2] = min(dp[i1][i2][j1][j2], dp[i1][i][j1][j2] + dp[i][i2][j1][j2] + sum); } for (int j = j1 + 1; j < j2; j++) { dp[i1][i2][j1][j2] = min(dp[i1][i2][j1][j2], dp[i1][i2][j1][j] + dp[i1][i2][j][j2] + sum); } } } } } cout << dp[0][h][0][w] << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...