#include <iostream>
using namespace std;
const int N=1e3+5,inf=0x7fffffff;
struct node{
int x,y,step;
}q[N*N];
int n,m,ox,oy;
int l,r;
char s[N][N];
int step[N][N][2];
int dx[4]={-1,1,0,0};
int dy[4]={0,0,-1,1};
bool ck(int x,int y){return x>=1 && x<=n && y>=1 && y<=m && s[x][y]!='#';}
void bfs(){
l=1;
step[1][1][0]=0;
q[++r]={1,1,0};
while(l<=r){
int x=q[l].x,y=q[l].y,st=q[l].step;
l++;
if(x==n && y==m) break;
int lx=x+ox,ly=y+oy;
if(ck(lx,ly) && st==0 && step[lx][ly][1]==-1){
q[++r]={lx,ly,1};
step[lx][ly][1]=step[x][y][0]+1;
}
for(int i=0; i<4; i++){
int fx=x+dx[i],fy=y+dy[i];
if(ck(fx,fy) && step[fx][fy][st]==-1){
q[++r]={fx,fy,st};
step[fx][fy][st]=step[x][y][st]+1;
}
}
}
}
signed main(){
scanf("%d%d%d%d",&n,&m,&ox,&oy);
for(int i=1; i<=n; i++)
scanf("%s",s[i]+1);
for(int i=1; i<=n; i++)
for(int j=1; j<=m; j++)
step[i][j][0]=step[i][j][1]=-1;
bfs();
if(step[n][m][0]==-1 && step[n][m][1]==-1) puts("-1");
else printf("%d\n",min(step[n][m][0]==-1 ? inf : step[n][m][0],step[n][m][1]==-1 ? inf : step[n][m][1]));
return 0;
}
rt,第二个死活过不去,有什么数据能hack掉我的代码吗/kel