This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <algorithm>
#include <cmath>
#include <iostream>
#include <sstream>
#include <set>
using namespace std;
int a[2323][2323];
int cost[2323][2323];
int from(int b, int c) {
return max(0, c-b+1);
}
int main()
{
int n;
scanf("%d", &n);
for (int i=0; i<n; i++)
for (int j=0; j<n; j++)
scanf("%d", &a[i][j]);
for (int i=0; i<n; i++)
for (int j=0; j<n; j++) {
if (i == 0 && j == 0) { cost[i][j] = 0; continue; }
cost[i][j] = 999999999;
if (i) cost[i][j] = min(cost[i][j], cost[i-1][j] + from(a[i-1][j], a[i][j]));
if (j) cost[i][j] = min(cost[i][j], cost[i][j-1] + from(a[i][j-1], a[i][j]));
}
printf("%d\n", cost[n-1][n-1]);
}
# | 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... |