#include <bits/stdc++.h>
using namespace std;
#define ll long long
int const N=92;
int const mod=1e9+7;
int hor[N][N],ver[N][N];
bool vis[N][N][N][N];
int n,m,l,k;
int rt,ct;
bool valid(int rh,int ch,int rv,int cv){
	if(vis[rh][ch][rv][cv])
		return 0;
	bool b=0;
	// if(rh==1){
	// 	cout<<rh<<' '<<ch<<' '<<rv<<' '<<cv<<endl;
	// 	cout<<"wer"<<endl;
	// 	b=1;
	// }
	if(rh<=0 || rh>m || rv<=0 || rv>m || ch<=0 || ch>n ||cv<=0 || cv>n)
		return 0;
	if(rv>rh || rv+(l-1)<rh || ch>cv || ch+(k-1)<cv || (rv+l)-1>m || (ch+k)-1>n){
		return 0;
	}
	if(hor[rh][ch-1]!=hor[rh][(ch-1)+k]){
		return 0;
	}
	if(ver[rv-1][cv]!=ver[(rv-1)+l][cv])
		return 0;
	return 1;
}
void dfs(int rh,int ch,int rv,int cv){
	if(valid(rh,ch,rv,cv)==0)
		return;
	vis[rh][ch][rv][cv]=1;
	// cout<<rh<<' '<<ch<<' '<<rv<<' '<<cv<<endl;
	if(rh==rt && cv==ct){
		cout<<"YES"<<endl;
		exit(0);
	}
	//hor
	dfs(rh+1,ch,rv,cv);
	dfs(rh-1,ch,rv,cv);
	dfs(rh,ch+1,rv,cv);
	dfs(rh,ch-1,rv,cv);
	dfs(rh,ch,rv+1,cv);
	dfs(rh,ch,rv-1,cv);
	dfs(rh,ch,rv,cv+1);
	dfs(rh,ch,rv,cv-1);
}
int main(){
	cin>>n>>m>>k>>l;
	int rh,ch,rv,cv;
	cin>>ch>>rh>>cv>>rv;
	rh++;ch++;cv++;rv++;
	for (int r = 1; r <=m; ++r)
	{
		string s;
		cin>>s;
		for (int c = 1; c <=n; c++)
		{
			if(s[c-1]=='*'){
				rt=r;
				ct=c;
			}
			else if(s[c-1]=='X'){
				hor[r][c]=1;
				ver[r][c]=1;
			}
		}
	}
	for (int i = 1; i <=m; ++i)
		for(int j=1;j<=n;j++)
			ver[i][j]+=ver[i-1][j];
	for (int i = 1; i <=m; ++i)
		for(int j=1;j<=n;j++)
			hor[i][j]+=hor[i][j-1];
	dfs(rh,ch,rv,cv);
	// cout<<hor[1][3-1]<<' '<<hor[1][(3-1)+k]<<endl;
	cout<<"NO"<<endl;
	return 0;
}
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... |