| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 348320 | Mefarnis | 건포도 (IOI09_raisins) | C++14 | 2070 ms | 53516 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define maxn 51
using namespace std;
typedef long long LL;
int n,m;
int ar[maxn][maxn];
int sum[maxn][maxn];
LL dp[maxn][maxn][maxn][maxn];
int query(int r1 , int c1 , int r2 , int c2) {
return sum[r2][c2] + sum[r1-1][c1-1] - sum[r2][c1-1] - sum[r1-1][c2];
}
LL f(int r1 , int c1 , int r2 , int c2) {
if(r1 == r2 && c1 == c2)
return 0;
if(dp[r1][c1][r2][c2] != -1)
return dp[r1][c1][r2][c2];
dp[r1][c1][r2][c2] = LLONG_MAX;
int add = query(r1,c1,r2,c2);
for( int c = c1 ; c < c2 ; c++ ) {
LL cost = f(r1,c1,r2,c) + f(r1,c+1,r2,c2) + add;
dp[r1][c1][r2][c2] = min(dp[r1][c1][r2][c2],cost);
}
for( int r = r1 ; r < r2 ; r++ ) {
LL cost = f(r1,c1,r,c2) + f(r+1,c1,r2,c2) + add;
dp[r1][c1][r2][c2] = min(dp[r1][c1][r2][c2],cost);
}
return dp[r1][c1][r2][c2];
}
int main() {
scanf("%d%d",&n,&m);
for( int i = 1 ; i <= n ; i++ )
for( int j = 1 ; j <= m ; j++ ) {
scanf("%d",&ar[i][j]);
sum[i][j] = sum[i-1][j] + sum[i][j-1] - sum[i-1][j-1] + ar[i][j];
}
memset(dp,-1,sizeof(dp));
printf("%lld\n",f(1,1,n,m));
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
