# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
366749 | kostia244 | 건포도 (IOI09_raisins) | C++17 | 1056 ms | 36332 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define all(x) begin(x), end(x)
const int maxn = 55;
int n, m, a[maxn][maxn], p[maxn][maxn];
int dp[maxn][maxn][maxn][maxn];
int f(int xl, int xr, int yl, int yr) {
int &ans = dp[xl][xr][yl][yr];
if(ans >= 0) return ans;
if(xl == xr && yl == yr) return 0;
ans = 1<<30;
for(int c = xl; c < xr; c++) ans = min(ans, f(xl, c, yl, yr) + f(c+1, xr, yl, yr));
for(int c = yl; c < yr; c++) ans = min(ans, f(xl, xr, yl, c) + f(xl, xr, c+1, yr));
--xl,--yl;ans += p[xr][yr] - p[xl][yr] - p[xr][yl] + p[xl][yl];
return ans;
}
int main() {
cin.tie(0)->sync_with_stdio(0);
cin >> n >> m;
for(int i = 1; i <= n; i++)
for(int j = 1; j <= m; j++)
cin >> a[i][j], p[i][j] = a[i][j] + p[i-1][j];
for(int i = 1; i <= n; i++)
for(int j = 1; j <= m; j++)
p[i][j] += p[i][j-1];
memset(dp, -1, sizeof dp);
cout << f(1, n, 1, m);
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |