Submission #893149

#TimeUsernameProblemLanguageResultExecution timeMemory
893149MackerRaisins (IOI09_raisins)C++17
100 / 100
354 ms29272 KiB
#include <bits/stdc++.h> //#pragma GCC optimize("Ofast") //#pragma GCC target("avx2") using namespace std; typedef long long ll; typedef long double ld; #define all(v) v.begin(), v.end() #define ckmin(a, b) a = min(a, b) int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, m; cin >> n >> m; vector<vector<vector<vector<int>>>> dp(n, vector<vector<vector<int>>>(m, vector<vector<int>>(n, vector<int>(m, INT_MAX/5)))); vector<vector<int>> sum(n + 1, vector<int>(m + 1)); vector<vector<int>> v(n, vector<int>(m)); sum.resize(n, vector<int>(m)); for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { cin >> v[i][j]; sum[i + 1][j + 1] = sum[i][j + 1] + sum[i + 1][j] - sum[i][j] + v[i][j]; dp[i][j][i][j] = 0; } } for (int w = 0; w < n; w++) for (int h = 0; h < m; h++) for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) { if(i + w >= n) continue; if(j + h >= m) continue; int s = sum[i + w + 1][j + h + 1] - sum[i + w + 1][j] - sum[i][j + h + 1] + sum[i][j]; for (int k = i; k < i + w; k++) { ckmin(dp[i][j][i + w][j + h], dp[i][j][k][j + h] + dp[k + 1][j][i + w][j + h] + s); } for (int k = j; k < j + h; k++) { ckmin(dp[i][j][i + w][j + h], dp[i][j][i + w][k] + dp[i][k + 1][i + w][j + h] + s); } } cout << dp[0][0][n - 1][m - 1] << "\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...