#include #include using namespace std; int H, W; int sx,sy,gx,gy; string field[150]; int check[150][150]; int dx[4] = { 0, 1, 0, -1}; int dy[4] = {-1, 0, 1, 0}; void dfs(int sy, int sx){ if(sx==gx-1&&sy==gy-1)return; for(int i=0;i<4;i++){ if (!check[sy+dy[i]][sx+dx[i]] && sx+dx[i] >= 0 && sx+dx[i] <= W && sy+dy[i] >= 0 && sy+dy[i] <= H){ if(field[sy][sx] - '0' == field[sy+dy[i]][sx+dx[i]] - '0'){ check[sy + dy[i]][sx + dx[i]] = check[sy][sx] + 1; dfs(sy + dy[i], sx + dx[i]); }else if (field[sy + dy[i]][sx + dx[i]] - '0' - 1 == field[sy][sx] - '0'){ cout << field[sy][sx] - '0' << endl; cout << field[sy + dy[i]][sx + dx[i]] - '0' << endl; check[sy + dy[i]][sx + dx[i]] = check[sy][sx] + 1; dfs(sy + dy[i], sx + dx[i]); }else if (field[sy + dy[i]][sx + dx[i]] - '0' < field[sy][sx] - '0'){ if (field[sy + dy[i]][sx + dx[i]] - '0' == field[sy][sx] - '0' - 1){ check[sy + dy[i]][sx + dx[i]] = check[sy][sx] + 1; dfs(sy + dy[i], sx + dx[i]); }else if (sx + dx[i] + dx[i] >= 0 && sx + dx[i] + dx[i] <= W && sy + dy[i] + dy[i] >= 0 && sy + dy[i] + dy[i] <= H && !check[sy + dy[i] + dy[i]][sx + dx[i] + dx[i]] && field[sy][sx] - '0' == field[sy + dy[i] + dy[i]][sx + dx[i] + dx[i]] - '0'){ check[sy + dy[i] + dy[i]][sx + dx[i] + dx[i]] = check[sy][sx] +1; dfs(sy + dy[i] + dy[i], sx + dx[i] + dx[i]); } } } } return; } int main(){ cin >> H >> W; cin>>sx>>sy>>gx>>gy; for(int i=0;i>field[i]; } cout<