#include<bits/stdc++.h>
using namespace std;
const long long int INF = 1e18;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n,m; cin >> n >> m;
vector<vector<long long int>> a(n, vector<long long int>(m));
for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) cin >> a[i][j];
vector<vector<long long int>> pref(n + 1, vector<long long int>(m + 1, 0));
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
pref[i + 1][j + 1] = pref[i + 1][j] + pref[i][j + 1] + a[i][j] - pref[i][j];
}
}
auto f = [&](int x1, int y1, int x2, int y2) -> long long int {
return pref[x2 + 1][y2 + 1] - pref[x2 + 1][y1] - pref[x1][y2 + 1] + pref[x1][y1];
};
vector dp(n, vector(n, vector(m, vector<int>(m, -1))));
auto solve = [&](auto self, int x1, int x2, int y1, int y2) -> long long int {
if (dp[x1][x2][y1][y2] != -1) return dp[x1][x2][y1][y2];
if (x1 == x2 && y1 == y2) return 0;
long long int lo = INF;
for (int i = x1; i < x2; i++) lo = min(lo, self(self, x1, i, y1, y2) + self(self, i + 1, x2, y1, y2));
for (int i = y1; i < y2; i++) lo = min(lo, self(self, x1, x2, y1, i) + self(self, x1, x2, i + 1, y2));
dp[x1][x2][y1][y2] = f(x1, y1, x2, y2) + lo;
};
cout << solve(solve, 0, n - 1, 0, m - 1);
}
컴파일 시 표준 에러 (stderr) 메시지
raisins.cpp: In lambda function:
raisins.cpp:34:3: warning: control reaches end of non-void function [-Wreturn-type]
34 | };
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |