# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
893149 | Macker | Raisins (IOI09_raisins) | C++17 | 354 ms | 29272 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |