Submission #8019

#TimeUsernameProblemLanguageResultExecution timeMemory
8019paulsohn배열 탈출 (GA8_array)C++98
100 / 100
660 ms39728 KiB
#include <stdio.h>
int n, A[2224][2224] = { 0 }, cost[2224][2224] = { 0 };
int main(){
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i){
        for (int j = 1; j <= n; ++j){
            scanf("%d", &A[i][j]);
        }
    }
    for (int i = n; i; --i){
        for (int j = n; j; --j){
            int rcost = cost[i][j + 1] + (A[i][j] > A[i][j + 1] ? 0 : A[i][j + 1] - A[i][j] + 1);
            int dcost = cost[i + 1][j] + (A[i][j] > A[i + 1][j] ? 0 : A[i + 1][j] - A[i][j] + 1);
            if (i == n && j == n) cost[n][n] = 0;
            else if (i == n) cost[n][j] = rcost;
            else if (j == n) cost[i][n] = dcost;
            else cost[i][j] = (rcost > dcost ? dcost : rcost);
        }
    }
    printf("%d\n", cost[1][1]);
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...