#include "wombats.h"
#include<stdlib.h>
#include<queue>
#include<vector>
#include<functional>
#include<string.h>
using namespace std;
#define X first
#define Y second
typedef pair<int,int> P;
typedef pair<int,P> Pi;
const int id = 512;
const int inf = 1e9;
const int bz = 10;
int H[5000][200],V[5000][200];
int T[1030][200][200];
int R,C;
void upd(int x,int y)
{
int i,j;
int A[200];
memset(A,0,sizeof(A));
for(i=x-1;i>=0;i--)A[i]=A[i+1]+H[bz*y][i];
for(i=x+1;i<C;i++)A[i]=A[i-1]+H[bz*y][i-1];
bool check[200];
for(i=bz*y+1;i<=bz*y+bz && i<R;i++){
priority_queue <P,vector<P>, greater<P> > pq;
memset(check,0,sizeof(check));
for(j=0;j<C;j++)pq.push(P(A[j]+V[i-1][j],j));
int cnt = 0;
while(!pq.empty() && cnt!=C){
P t = pq.top();
pq.pop();
if(check[t.Y])continue;
check[t.Y]=1;
A[t.Y]=t.X;
cnt++;
if(t.Y+1<C && !check[t.Y+1])pq.push(P(t.X+H[i][t.Y],t.Y+1));
if(t.Y!=0 && !check[t.Y-1])pq.push(P(t.X+H[i][t.Y-1],t.Y-1));
}
}
for(i=0;i<C;i++)T[id+y][x][i]=A[i];
}
void Union(int t)
{
int i,j,k;
int sk[200];
for(i=0;i<C;i++)sk[i]=0;
for(i=0;i<C;i++)for(j=0;j<C;j++)T[t][i][j]=inf;
for(i=C-1;i>=-C+1;i--){
for(j=min(C-1,C-i-1);j>=0&&j+i>=0;j--){
int s=j==max(0,-i)?0:sk[j-1];
int d=j==min(C-1,C-i-1)?C-1:sk[j];
for(k=s;k<=d;k++){
if(T[t][j][j+i] > T[t<<1][j][k] + T[t<<1|1][k][j+i]){
T[t][j][j+i]=T[t<<1][j][k] + T[t<<1|1][k][j+i];
sk[j]=k;
}
}
}
}
for(i=0;i<C;i++)if(T[t][i][i]==inf)T[t][i][i]=0;
}
void init(int R, int C, int H_[5000][200], int V_[5000][200]){
int i,j;
for(i=0;i<R;i++)for(j=0;j<C-1;j++)H[i][j]=H_[i][j];
for(i=0;i<R-1;i++)for(j=0;j<C;j++)V[i][j]=V_[i][j];
::R=R;
::C=C;
for(i=0;i<C;i++){
for(j=0;bz*j<R;j++){
upd(i,j);
}
for(;j<id;j++){
for(int u=0;u<C;u++)T[id+j][i][u]=i==u?0:inf;
}
}
for(i=id-1;i;i--)Union(i);
}
void changeH(int P, int Q, int W){
H[P][Q]=W;
int i,r=P/bz;
for(i=0;i<C;i++)upd(i,r);
if(P%bz == 0){
for(i=0;i<C;i++)upd(i,r-1);
int t=(r+id-1)/2;
while(t){Union(t);t>>=1;}
}
r+=id;
r>>=1;
while(r){
Union(r);
r>>=1;
}
}
void changeV(int P, int Q, int W) {
V[P][Q]=W;
int i,r=P/bz;
for(i=0;i<C;i++)upd(i,r);
r+=id;
r>>=1;
while(r){
Union(r);
r>>=1;
}
}
int escape(int V1, int V2){
return T[1][V1][V2];
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
177772 KB |
Output is correct |
2 |
Correct |
4 ms |
177772 KB |
Output is correct |
3 |
Correct |
84 ms |
177772 KB |
Output is correct |
4 |
Correct |
8 ms |
177772 KB |
Output is correct |
5 |
Correct |
0 ms |
177772 KB |
Output is correct |
6 |
Correct |
0 ms |
177772 KB |
Output is correct |
7 |
Correct |
0 ms |
177772 KB |
Output is correct |
8 |
Correct |
0 ms |
177772 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
177772 KB |
Output is correct |
2 |
Correct |
0 ms |
177772 KB |
Output is correct |
3 |
Correct |
0 ms |
177772 KB |
Output is correct |
4 |
Correct |
4 ms |
177772 KB |
Output is correct |
5 |
Correct |
4 ms |
177772 KB |
Output is correct |
6 |
Correct |
4 ms |
177772 KB |
Output is correct |
7 |
Correct |
8 ms |
177772 KB |
Output is correct |
8 |
Correct |
0 ms |
177772 KB |
Output is correct |
9 |
Correct |
4 ms |
177772 KB |
Output is correct |
10 |
Correct |
8 ms |
177772 KB |
Output is correct |
11 |
Correct |
80 ms |
177772 KB |
Output is correct |
12 |
Correct |
4 ms |
177772 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2204 ms |
177772 KB |
Output is correct |
2 |
Correct |
1016 ms |
177772 KB |
Output is correct |
3 |
Incorrect |
2472 ms |
177772 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
177772 KB |
Output is correct |
2 |
Correct |
12 ms |
177772 KB |
Output is correct |
3 |
Correct |
8 ms |
177772 KB |
Output is correct |
4 |
Correct |
48 ms |
177772 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2232 ms |
177772 KB |
Output is correct |
2 |
Correct |
1000 ms |
177772 KB |
Output is correct |
3 |
Incorrect |
2452 ms |
177772 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2200 ms |
177772 KB |
Output is correct |
2 |
Correct |
984 ms |
177772 KB |
Output is correct |
3 |
Incorrect |
2452 ms |
177772 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |