#include #define syosu(x) fixed< P; typedef pair pdd; typedef pair pll; typedef vector vi; typedef vector vvi; typedef vector vd; typedef vector vvd; typedef vector vl; typedef vector vvl; typedef vector vs; typedef vector

vp; typedef vector vvp; typedef vector vpll; typedef pair pip; typedef vector vip; const int inf=1<<30; const ll INF=1ll<<60; const double pi=acos(-1); const double eps=1e-8; const ll mod=1e9+7; //const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1}; class Graph{ private: int n; vvp g; public: int DIJ(int s,int t){ priority_queue

q; vi d(n,inf); d[s]=0; q.push({0,s}); while(!q.empty()){ P p=q.top(); q.pop(); int v=p.second; if(d[v]<-p.first) continue; for(auto i:g[v]){ int u=i.first,D=d[v]+i.second; if(d[u]>D){ d[u]=D; q.push({-D,u}); } } } return d[t]; } Graph(int v){ n=v; g=vvp(v); } void add_edge(int s,int t,int c=1){ g[s].push_back({t,c}); } }; const int dx[8]={2,1,-1,-2,-2,-1,1,2},dy[8]={1,2,2,1,-1,-2,-2,-1}; const int DX[4]={1,1,-1,-1},DY[4]={1,-1,1,-1}; int h,w,I,J; vvi a; int main(){ cin>>h>>w; a=vvi(h,vi(w)); for(int i=0;i>c; if(c=='S') I=i*w+j; if(c=='G') J=i*w+j; if(c=='R') a[i][j]=-1; } Graph g(2*h*w); for(int i=0;i=0&&x=0&&y=0&&x=0&&y