#include "wombats.h"
#include <bits/stdc++.h>
using namespace std;
int n,c,x;
int h[5000][200],v[5000][200];
using mat=int[200][200];
mat dp[2];
void calc(int l,int r){
for(int i=0;i<c;i++){
for(int j=0;j<c;j++){
dp[0][i][j]=2e9;
}
dp[0][i][i]=0;
}
if(1<c){
for(int i=1;i<c;i++){
for(int j=0;j<i;j++){
dp[0][i][j]=min(dp[0][i][j],dp[0][i-1][j]+h[r][i-1]);
}
}
for(int i=c-2;0<=i;i--){
for(int j=c-1;i<j;j--){
dp[0][i][j]=min(dp[0][i][j],dp[0][i+1][j]+h[r][i]);
}
}
}
x=0;
for(int i=r-1;l<=i;i--){
x=!x;
for(int j=0;j<c;j++){
for(int k=0;k<c;k++){
dp[x][j][k]=dp[!x][j][k]+v[i][j];
}
}
if(1<c){
for(int j=1;j<c;j++){
for(int k=0;k<c;k++){
dp[x][j][k]=min(dp[x][j][k],dp[x][j-1][k]+h[i][j-1]);
}
}
for(int j=c-2;0<=j;j--){
for(int k=0;k<c;k++){
dp[x][j][k]=min(dp[x][j][k],dp[x][j+1][k]+h[i][j]);
}
}
}
}
}
struct{
mat tree[500];
#define cur tree[node]
void build(int l,int r,int node){
if(r-l<50){
calc(l,r+1);
for(int i=0;i<c;i++){
for(int j=0;j<c;j++){
cur[i][j]=dp[x][i][j];
}
}
return;
}
int mid=(l+r)>>1,child=node<<1;
build(l,mid,child),build(mid+1,r,child|1);
for(int i=0;i<c;i++){
for(int j=0;j<c;j++){
cur[i][j]=INT_MAX;
for(int k=0;k<c;k++){
cur[i][j]=min(cur[i][j],tree[child][i][k]+tree[child|1][k][j]);
}
}
}
}
int P;
void update(int l,int r,int node){
if(r-l<50){
calc(l,r+1);
for(int i=0;i<c;i++){
for(int j=0;j<c;j++){
cur[i][j]=dp[x][i][j];
}
}
return;
}
int mid=(l+r)>>1,child=node<<1;
if(P<=mid)update(l,mid,child);
else update(mid+1,r,child|1);
for(int i=0;i<c;i++){
for(int j=0;j<c;j++){
cur[i][j]=INT_MAX;
for(int k=0;k<c;k++){
cur[i][j]=min(cur[i][j],tree[child][i][k]+tree[child|1][k][j]);
}
}
}
}
void update(int p){
P=p;
update(0,n-2,1);
}
}st;
void init(int R, int C, int H[5000][200], int V[5000][200]) {
n=R;
c=C;
for(int i=0;i<n;i++){
for(int j=0;j<c;j++){
h[i][j]=H[i][j];
v[i][j]=V[i][j];
}
}
st.build(0,n-2,1);
}
void changeH(int P, int Q, int W) {
h[P][Q]=W;
st.update(P);
}
void changeV(int P, int Q, int W) {
v[P][Q]=W;
st.update(P);
}
int escape(int V1, int V2) {
return st.tree[1][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 |
7 ms |
13144 KB |
Output is correct |
2 |
Correct |
7 ms |
13148 KB |
Output is correct |
3 |
Correct |
45 ms |
16012 KB |
Output is correct |
4 |
Correct |
5 ms |
13148 KB |
Output is correct |
5 |
Correct |
5 ms |
13264 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
604 KB |
Output is correct |
5 |
Correct |
1 ms |
604 KB |
Output is correct |
6 |
Correct |
0 ms |
604 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
604 KB |
Output is correct |
10 |
Correct |
0 ms |
604 KB |
Output is correct |
11 |
Correct |
38 ms |
2940 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
184 ms |
1116 KB |
Output is correct |
2 |
Correct |
178 ms |
1116 KB |
Output is correct |
3 |
Correct |
183 ms |
1112 KB |
Output is correct |
4 |
Correct |
168 ms |
1224 KB |
Output is correct |
5 |
Correct |
162 ms |
1112 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
912 ms |
1256 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
7 ms |
17384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
177 ms |
1116 KB |
Output is correct |
2 |
Correct |
187 ms |
1244 KB |
Output is correct |
3 |
Correct |
189 ms |
1256 KB |
Output is correct |
4 |
Correct |
187 ms |
1084 KB |
Output is correct |
5 |
Correct |
181 ms |
1112 KB |
Output is correct |
6 |
Incorrect |
8 ms |
17496 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
188 ms |
1116 KB |
Output is correct |
2 |
Correct |
181 ms |
1240 KB |
Output is correct |
3 |
Correct |
190 ms |
1112 KB |
Output is correct |
4 |
Correct |
188 ms |
1372 KB |
Output is correct |
5 |
Correct |
180 ms |
1116 KB |
Output is correct |
6 |
Incorrect |
8 ms |
17496 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |