#include #include #include #include #include #include #include #include using namespace std; #define FOR(i,a,b) for (int i=(a);i<(b);i++) #define FORR(i,a,b) for (int i=(b)-1;i>=(a);i--) #define rep(i,n) for (int i=0;i<(n);i++) #define Rrep(i,n) for (int i=(n)-1;i>=0;i--) #define pb push_back #define ALL(a) (a).begin(),(a).end() #define PI 3.1415926535 typedef long long ll; typedef pair P; const int INF = 99999999; const int MAX_H = 500; const int MAX_W = 500; int H, W; vector field; bool inside(int x, int y) { return 0 <= x && x < H && 0 <= y && y < W; } int main() { /* assert code */ cin >> H >> W; assert(1 <= H && H <= MAX_H); assert(1 <= W && W <= MAX_W); field.clear(); field.resize(H); // 盤面の読み込み & スタート位置、ゴール位置の取得 int sx = -1, sy = -1, gx = -1, gy = -1; int cntS = 0, cntG = 0; rep(i, H) { cin >> field[i]; assert(field[i].size() == W); rep(j, W) { if (field[i][j] == 'S') { sx = i; sy = j; cntS++; } else if (field[i][j] == 'G') { gx = i; gy = j; cntG++; } else { assert(field[i][j] == '.' || field[i][j] == 'R'); } } } assert(inside(sx, sy)); assert(inside(gx, gy)); assert(cntS == 1); assert(cntG == 1); }