이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "wombats.h"
#include <cstdlib>
#include <cstdio>
#include <queue>
#include <cstring>
using namespace std;
static const int bucket=10;
static const int MAXN=1<<9;
static const int MAXC=200;
static int idx[2*MAXN][MAXC][MAXC]; //78.125MB
static int R;
static int C;
static int H[MAXN*bucket][MAXC];//3.90625MB
static int V[MAXN*bucket][MAXC];//3.90625MB
static void dijkFunction(int a)
{
int saveidx=a+MAXN;
int bias=a*bucket;
int dijk[bucket+1][MAXC];
if(bias>=R)
{
idx[saveidx][0][0]=-1;
return;
}
for(int i=0;i<C;i++)
{
memset(dijk,-1,sizeof(dijk) );
priority_queue<pair<int,pair<int,int> > > PQ;
PQ.push(make_pair(-0,make_pair(0,i)));
while(!PQ.empty())
{
int dist=-PQ.top().first;
int xcord=PQ.top().second.first;
int ycord=PQ.top().second.second;
PQ.pop();
if(dijk[xcord][ycord]!=-1) continue;
dijk[xcord][ycord]=dist;
if(xcord==bucket) continue;
if(xcord==R-bias) continue;
if(xcord!=R-bias-1) PQ.push(make_pair(-(dist+V[xcord+bias][ycord]),make_pair(xcord+1,ycord)));
if(ycord!=0)
PQ.push(make_pair(-(dist+H[xcord+bias][ycord-1]),make_pair(xcord,ycord-1)));
if(ycord!=C-1)
PQ.push(make_pair(-(dist+H[xcord+bias][ycord]),make_pair(xcord,ycord+1)));
}
for(int j=0;j<C;j++)
idx[saveidx][i][j]=dijk[min(R-1-bias,bucket)][j];
}
}
static void updateidx(int ind)
{
int ind1=ind*2, ind2=ind*2+1;
if(idx[ind2][0][0]<0)
{
for(int i=0;i<C;i++)
for(int j=0;j<C;j++)
idx[ind][i][j]=idx[ind1][i][j];
return;
}
for(int imj=1-C;imj<=C-1;imj++)
{
int k=0; // using k as path
for(int i=0;i<C;i++)
{
int j=i-imj;
if(j<0 || j>=C) continue;
while(k<C-1)
{
if(idx[ind1][i][k]+idx[ind2][k][j]<=idx[ind1][i][k+1]+idx[ind2][k+1][j]) break;
k++;
}
idx[ind][i][j]=idx[ind1][i][k]+idx[ind2][k][j];
}
}
/*
//red herring
for(int i=0;i<C;i++)
for(int j=0;j<C;j++)
{
idx[ind][i][j]=0x3f3f3f3f;
for(int k=0;k<C;k++)
idx[ind][i][j]=min(idx[ind][i][j],idx[ind1][i][k]+idx[ind2][k][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];
for(int i=0;i<MAXN;i++) dijkFunction(i);
for(int i=MAXN-1;i>0;i--)
updateidx(i);
}
static void refresh(int a)
{
dijkFunction(a);
a+=MAXN;
while(a!=1)
{
a/=2;
updateidx(a);
}
return;
}
void changeH(int P, int Q, int W)
{
int rbucket=P/bucket;
H[P][Q]=W;
refresh(rbucket);
}
void changeV(int P, int Q, int W)
{
int rbucket=P/bucket;
V[P][Q]=W;
refresh(rbucket);
}
int escape(int V1, int V2)
{
return idx[1][V1][V2];
}
# | 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... |