#include using namespace std; #include #include #include #include #include template inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } #define rep(i,n) for (int i = 0; i < (n); ++i) typedef long long ll; typedef unsigned long long ull; using P=pair; const ll INF=1e18; const int mod=998244353; struct edge{ int to; ll w; edge(int to,ll w):to(to),w(w){} }; using Graph=vector>; int n; ll h,w,k,p,xs,ys,xt,yt; int toid(int i,int j){return i*w+j;} ll dijkstra(int s,Graph G){ vector dist(n,INF); dist[s]=0; priority_queue,vector>,greater>>q; q.push({dist[s],s}); while(!q.empty()){ int v=q.top().second; ll d=q.top().first; q.pop(); if(d>dist[v]){continue;} for(auto e:G[v]){ if(chmin(dist[e.to],dist[v]+e.w)){ q.push({dist[e.to],e.to}); } } } return dist[toid(yt,xt)]; } char c[105][105]; int dx[4]={0,0,1,-1},dy[4]={-1,1,0,0}; void solve(){ cin>>h>>w; vectors(4); rep(i,4){cin>>s[i];} cin>>k>>p>>xs>>ys>>xt>>yt; xs--;ys--;xt--;yt--; n=h*w; Graph G(n); rep(i,h){ rep(j,w){ cin>>c[i][j]; } } rep(i,h){ rep(j,w){ if(c[i][j]=='#'){continue;} rep(k,4){ int ni=i+dy[k],nj=j+dx[k]; if(ni>=0&&ni=0&&nj