#include <bits/stdc++.h>
using namespace std;
const int mmod = 998244353;
#define vl vector<int>
#define vint vector<vector<int>>
int intersect(int l1, int r1, int l2, int r2){
int c =0;
return max(c, (min(r1,r2) - max(l1,l2) + 1));
}
vector<vector<bool>> visited;
int w,h,k,l;
vector<string> graf;
vint leva;
vint prava;
vint up;
vint down;
void dfs(int y, int x){
visited[y][x] = true;
vint dirs = {{1,0},{-1,0},{0,1},{0,-1}};
if (graf[y][x] == '*'){
cout << "YES";
exit(0);
}
for (int i = 0; i < 4; i++){
int nx, ny;
nx = x + dirs[i][0];
ny = y + dirs[i][1];
if (nx >= 0 && ny >= 0 && nx < w && ny < h && graf[ny][nx] != 'X'){
if (visited[ny][nx] == false){
if (intersect(x - prava[y][x], x + leva[y][x], nx - prava[ny][nx], nx + leva[ny][nx]) >= k){
if (intersect(y - down[y][x], y + up[y][x], ny - down[ny][nx], ny + up[ny][nx]) >= l){
dfs(ny, nx);
}
}
}
}
}
}
int main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
cin >> w >> h >> k >> l;
int kx, ky, lx, ly;
cin >> kx >> ky >> lx >> ly; //k-horiznot a l-vertikal
for (int i = 0; i < h; i++){
string radek;
cin >> radek;
graf.push_back(radek);
}
for (int i = 0; i < h; i++){
vector<bool> radek;
for (int j = 0; j < w; j++){
radek.push_back(false);
}
visited.push_back(radek);
}
// Kontrola, že se vejdou
for (int i = 0; i < h; i++){
vl radek;
for (int j = 0; j < w; j++){
radek.push_back(0);
}
leva.push_back(radek);
prava.push_back(radek);
up.push_back(radek);
down.push_back(radek);
}
for (int i = 0; i < w; i++){
int aktual1, aktual2;
aktual1 = 0; aktual2 = 0;
for (int j = 0; j < h; j++){
if (graf[j][i] != 'X'){
down[j][i] = aktual1;
aktual1++;
}
else{
aktual1 = 0;
}
}
for (int j = h-1; j >= 0; j--){
if (graf[j][i] != 'X'){
up[j][i] = aktual2;
aktual2++;
}
else{
aktual2 = 0;
}
}
}
for (int i = 0; i < h; i++){
int aktual1 = 0; int aktual2 = 0;
for (int j = 0; j < w; j++){
if (graf[i][j] != 'X'){
prava[i][j] = aktual1;
aktual1++;
}
else{
aktual1 = 0;
}
}
for (int j = w-1; j >= 0; j--){
if (graf[i][j] != 'X'){
leva[i][j] = aktual2;
aktual2++;
}
else{
aktual2 = 0;
}
}
}
dfs(ky, lx);
cout << "NO";
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... |