终于1a了,啊,好长时间没有这种感觉了,这题没有甚么需要注意得,不然不可能1a
#include<iostream>
#include<cstring>
#include<cstdio>
#include<queue>
using namespace std;
const int Maxn = 1000010;
const __int64 inf = 1999999999;
int n, sx, sy, ex, ey;
int di[][2] = {1, 0, -1, 0, 0, -1, 0, 1};
int w_dis[2][Maxn], lane[Maxn];
__int64 dis[2][Maxn];
bool vis[2][Maxn];
struct node {
int x, y;
__int64 dis;
bool operator < (const node &b)const {
return dis > b.dis;
}
};
void ini() {
for(int i = 0; i <= n; ++ i)
{
vis[0][i] = vis[1][i] = false;
dis[1][i] = dis[0][i] = inf;
}
}
bool inmap(int x,int y) {
if(0<=x&&x<=1&&y>=0&&y<=n)
return true;
else
return false;
}
void dij() {
priority_queue<node> q;
node now, next;
now.x = sx, now.y = sy, dis[sx][sy] = 0, now.dis = 0;
q.push(now);
while(!q.empty()) {
now = q.top();
q.pop();
if(vis[now.x][now.y])
continue;
vis[now.x][now.y] = true;
if(now.x == ex&&now.y == ey)
break;
int x, y;
for(int i = 0; i < 4; ++i)
{
x = now.x + di[i][0]; y = now.y + di[i][1];
if(!inmap(x,y))
continue;
if(i < 2)//表示上下位移
{
if(!vis[x][y] && dis[now.x][now.y] + lane[now.y] < dis[x][y])
{
dis[x][y] = dis[now.x][now.y] + lane[now.y];
next.x = x, next.y = y, next.dis = dis[x][y];
q.push(next);
}
}
else
{
if(i == 2)
{
if(!vis[x][y] && dis[now.x][now.y] + w_dis[now.x][y] < dis[x][y])
{
dis[x][y] = dis[now.x][now.y] + w_dis[now.x][y];
next.x = x, next.y = y, next.dis = dis[x][y];
q.push(next);
}
}
else {
if(!vis[x][y] && dis[now.x][now.y] + w_dis[now.x][now.y] < dis[x][y])
{
dis[x][y] = dis[now.x][now.y] + w_dis[now.x][now.y];
next.x = x, next.y = y, next.dis = dis[x][y];
q.push(next);
}
}
}
}
}
}
int main(void)
{
while(scanf("%d",&n),n)
{
ini();
scanf("%d%d%d%d",&sx,&sy,&ex,&ey);
for(int i = 0; i < n; ++i )
scanf("%d",&w_dis[0][i]);
for(int i = 0; i <= n; ++i)
scanf("%d",&lane[i]);
for(int i = 0; i < n; i++)
scanf("%d",&w_dis[1][i]);
dij();
cout<<dis[ex][ey]<<endl;
}
return 0;
}