#include<bits/stdc++.h> using namespace std; const int M=1e3+5; int n,m; int dx[5]={0,0,1,-1}; int dy[5]={1,-1,0,0}; int dp[M][M][5][2]; char mp[M][M]; struct P { int x,y,step; }; bool check(int x,int y) { if(x<1||x>n||y<1||y>m||mp[x][y]=='X')return false; return true; } void bfs(i...