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 "wombats.h"
#include <bits/stdc++.h>
#define R 5000
#define C 20
using namespace std;
int dp[C][R][C];
int r,c;
int h[R][C];
int v[R][C];
int preh[R][C];
void build(){
for(int i = 0;i<r;i++){
for(int j = 0;j<c;j++){
preh[i][j] = h[i][j] + (j == 0?0:preh[i][j-1]);
}
}
for(int x = 0;x<c;x++){
for(int i = 0;i<r;i++){
for(int j = 0;j<c;j++){
dp[x][i][j] = 1e9;
}
}
for(int i = 0;i<c;i++){
dp[x][0][i] = abs((x == 0?0:preh[0][x-1]) - (i == 0?0:preh[0][i-1]));
}
for(int i = 0;i<r-1;i++){
for(int j = 0;j<c;j++){
// if(x == 2){
// cout << i << " " << j << " " << dp[x][i][j] << endl;
// }
for(int d = 0;d<c;d++){
int cost = v[i][j];
cost += abs((j == 0?0:preh[i+1][j-1]) - (d == 0?0:preh[i+1][d-1]));
dp[x][i+1][d] = min(dp[x][i+1][d], dp[x][i][j] + cost);
}
}
}
}
}
void init(int r_, int c_, int h_[5000][200], int v_[5000][200]) {
r = r_;
c = c_;
for(int i = 0;i<r;i++){
for(int j = 0;j<c;j++){
h[i][j] = h_[i][j];
v[i][j] = v_[i][j];
}
}
build();
}
void changeH(int p, int q, int w) {
h[p][q] = w;
build();
}
void changeV(int p, int q, int w) {
v[p][q] = w;
build();
}
int escape(int v1, int v2) {
return dp[v1][r-1][v2];
}
Compilation message (stderr)
grader.c: In function 'int main()':
grader.c:15:6: warning: variable 'res' set but not used [-Wunused-but-set-variable]
15 | int res;
| ^~~
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |