이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<stdio.h>
int n, A[2224][2224]={0};
int cost(int r, int c){
if(r>n || c>n)return 1e8;
int h,v;
if(r==n && c==n) return 0;
h=(A[r][c]>A[r][c+1] ? 0 : A[r][c+1]-A[r][c]+1);
if(r==n) return h+cost(r,c+1);
h+=cost(r,c+1);
v=(A[r][c]>A[r+1][c] ? 0 : A[r+1][c]-A[r][c]+1);
if(c==n) return v+cost(r+1,c);
v+=cost(r+1,c);
if(h>v) return v;
return h;
}
int main(){
int i,j;
scanf("%d", &n);
for(i=1;i<=n;++i){
for(j=1;j<=n;++j){
scanf("%d", &A[i][j]);
}
}
printf("%d\n", cost(1,1));
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... |