이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <cstdio>
#include <algorithm>
using namespace std;
const int MAX = 2300, INF = 1234567890;
int n, map[MAX][MAX];
void input(){
scanf("%d", &n);
int i, j;
for(i = 1; i<=n; i++){
for(j = 1; j<=n; j++){
scanf("%d", &map[i][j]);
}
}
}
int cost[MAX][MAX];
void solve(){
int i, j;
for(i = 1; i<=n; i++){
for(j = 1; j<=n; j++){
if(i == 1 && j == 1) continue;
cost[i][j] = INF;
if(i > 1) cost[i][j] = min(cost[i][j], cost[i-1][j]+max(0, map[i][j]-map[i-1][j]+1));
if(j > 1) cost[i][j] = min(cost[i][j], cost[i][j-1]+max(0, map[i][j]-map[i][j-1]+1));
}
}
printf("%d\n", cost[n][n]);
}
int main(){
input();
solve();
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |