#include #include #include #include #include #define SHOWVECTOR2 {std::cout << "----" << "\n";for(auto i : P){for(auto j : i){std::cout << std::setw(2) << j.depth << " ";}std::cout << "\n";}} using ll = long long int; typedef struct{ int y, x; bool visitedN, visitedB; bool isRed; int depth; bool thenN; }Pos; int main(){ std::ios::sync_with_stdio(false); std::cin.tie(0); int h, w; std::cin >> h >> w; std::vector> P(h, std::vector(w)); int sy, sx; int gy, gx; #define INIT(b) {P[i][j].y=i; P[i][j].x=j; P[i][j].visitedN=false; P[i][j].visitedB=false; P[i][j].isRed=(b); P[i][j].depth=-1; P[i][j].thenN=!(b);} for(int i=0; i> input; switch(input){ case 'S': sy=i; sx=j; INIT(false); break; case 'G': gy=i; gx=j; INIT(false); break; case '.': INIT(false); break; case 'R': INIT(true); break; } } } #undef INIT std::queue search; P[sy][sx].visitedN=true; P[sy][sx].thenN=true; P[sy][sx].depth=0; search.push(P[sy][sx]); std::vector moveN({-1, -2, -2, -1, -2, 1, -1, 2, 1, 2, 2, 1, 2, -1, 1, -2}); std::vector moveB({-1, -1, -1, 1, 1, 1, 1, -1}); while(!search.empty() && P[gy][gx].depth==-1){ Pos now = search.front(); search.pop(); if(now.thenN){ for(int i=0; i<8; ++i){ int searchY = now.y+moveN[i*2]; int searchX = now.x+moveN[i*2+1]; if(searchY>=0 && searchY=0 && searchX=0 && searchY=0 && searchX