#include #include #include #include using namespace std; #define rep(i,a,b) for(int i=(a);i<(b);i++) #define pb push_back #define tpl tuple int main(void) { int h, w, sy, sx, gy, gx, n, qy, qx, x, y; string s[500]; bool b[500][500][2] = {}, f; int km[8][2] = { {2,1},{1,2},{-1,2},{-2,1},{-2,-1},{-1,-2},{1,-2},{2,-1} }; int bm[4][2] = { {1,1},{-1,1},{-1,-1},{1,-1} }; queue q;// is_knight node y x cin >> h >> w; rep(i,0,h) cin >> s[i]; rep(i,0,h) rep(j,0,w) { if(s[i][j]=='S') { sy = i; sx = j; } if(s[i][j]=='G') { gy = i; gx = j; } } q.push(make_tuple(true,0,sy,sx)); while(q.size()) { f = get<0>(q.front()); n = get<1>(q.front()); qy = get<2>(q.front()); qx = get<3>(q.front()); q.pop(); if(f) { rep(i,0,8) { y = qy+km[i][0]; x = qx+km[i][1]; if(y>=0 && y=0 && x=0 && y=0 && x