#include "wombats.h"
#include <bits/stdc++.h>
using namespace std;
const int R_MAX = 5000;
const int C_MAX = 200;
const int K = 10;
const int R_DIV_K_MUL_2 = 1024;
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];
int st[R_DIV_K_MUL_2][C_MAX][C_MAX], OPT[C_MAX][C_MAX];
bool chmin(int& x, int y){
if(x > y){
x = y; return true;
}
return false;
}
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;
}
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];
}
}
}
int opt(int i, int j){
if(i < 0 || j < 0) return 0;
if(i >= C || j >= C) return C - 1;
return OPT[i][j];
}
void st_merge(int v, int vl, int vr){
for(int i = 0; i < C; i++) for(int j = 0; j < C; j++) st[v][i][j] = INF;
for(int d = -C; d <= C; d++){
for(int i = 0; i < C; i++){
int j = i + d; if(j < 0 || j >= C) continue;
for(int k = opt(i - 1, j); k <= opt(i, j + 1); k++){
if(st[v][i][j] > st[vl][i][k] + st[vr][k][j]) OPT[i][j] = k, st[v][i][j] = st[vl][i][k] + st[vr][k][j];
}
}
}
}
void st_update(int p, int v, int l, int r){
if(l == r){
for(int i = 0; i < C; i++) for(int j = 0; j < C; j++) st[v][i][j] = DP[i][j];
return;
}
int m = (l + r) / 2;
if(p <= m) st_update(p, v * 2 + 1, l, m);
else st_update(p, v * 2 + 2, m + 1, r);
st_merge(v, v * 2 + 1, v * 2 + 2);
}
void recalc(int part = -1){
if(part == -1){
for(int p = 0; p < R / K; p++) recalc(p);
return;
}
init();
for(int r = part * K; r < (part + 1) * K; r++){
process(r);
}
st_update(part, 0, 0, R / K - 1);
}
void init(int R, int C, int H[5000][200], int V[5000][200]) {
::R = (R + K - 1) / K * K, ::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 = R; i < ::R; i++){
for(int j = 0; j < C - 1; j++){
::H[i][j] = INF;
}
}
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 st[0][V1][V2];
}
Compilation message
grader.c: In function 'int main()':
grader.c:15:6: warning: variable 'res' set but not used [-Wunused-but-set-variable]
15 | int res;
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
12372 KB |
Output is correct |
2 |
Correct |
7 ms |
12484 KB |
Output is correct |
3 |
Correct |
58 ms |
14160 KB |
Output is correct |
4 |
Correct |
6 ms |
12500 KB |
Output is correct |
5 |
Correct |
6 ms |
12372 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
312 KB |
Output is correct |
3 |
Correct |
1 ms |
312 KB |
Output is correct |
4 |
Incorrect |
1 ms |
444 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
91 ms |
2436 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
9 ms |
21116 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
90 ms |
2424 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
89 ms |
2428 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |