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>
using namespace std;
const int R_MAX = 5000;
const int C_MAX = 200;
const int K = 50;
const int INF = 1 << 30;
int R, C, H[R_MAX][C_MAX], V[R_MAX][C_MAX];
int A[R_MAX / K][C_MAX][C_MAX], B[C_MAX][C_MAX];
int DP[C_MAX][C_MAX];
void init(){
for(int i = 0; i < C; i++) for(int j = 0; j < C; j++) DP[i][j] = i == j ? 0 : INF;
}
bool chmin(int& x, int y){
if(x > y){
x = y; return true;
}
return false;
}
void process(int row){
for(int i = 0; i < C; i++){
for(int j = 0; j < C; j++){
for(int k = j - 1; k >= 0; k--){
if(!chmin(DP[i][k], DP[i][k + 1] + H[row][k])){
break;
}
}
for(int k = j + 1; k < C; k++){
if(!chmin(DP[i][k], DP[i][k - 1] + H[row][k - 1])){
break;
}
}
}
}
for(int i = 0; i < C; i++){
for(int j = 0; j < C; j++){
DP[i][j] += V[row][j];
}
}
}
void recalc(int part = -1){
init();
for(int r = 0; r < R; r++){
process(r);
}
for(int i = 0; i < C; i++)
for(int j = 0; j < C; j++)
B[i][j] = DP[i][j];
}
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 - 1; j++){
::H[i][j] = H[i][j];
}
}
for(int i = 0; i < R - 1; i++){
for(int j = 0; j < C; j++){
::V[i][j] = V[i][j];
}
}
recalc();
}
void changeH(int P, int Q, int W) {
::H[P][Q] = W;
recalc(P / K);
}
void changeV(int P, int Q, int W) {
::V[P][Q] = W;
recalc(P / K);
}
int escape(int V1, int V2) {
return B[V1][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... |