#include <bits/stdc++.h>
using namespace std;
const int N = 1505;
int n, m, k, l, sx, sy, garbage, dp[N][N][4];
char mat[N][N];
bool vis[N][N], yes;
int dx[4] = {0, -1, 0, 1};
int dy[4] = {-1, 0, 1, 0};
// L U R D
bool valid(int x, int y){
return (0 <= x and x < n and 0 <= y and y < m and mat[x][y] != 'X');
}
int intersection(int l1, int r1, int l2, int r2){
return max(0, min(r1, r2) - max(l1, l2) + 1);
}
void dfs(int x, int y){
vis[x][y] = 1;
if (mat[x][y] == '*')
yes = 1;
for (int i = 0; i < 4; i ++){
int nx = x + dx[i];
int ny = y + dy[i];
if (!valid(nx, ny) or vis[nx][ny]) continue;
if (intersection(y - dp[x][y][0] + 1, y + dp[x][y][2] - 1, ny - dp[nx][ny][0] + 1, ny + dp[nx][ny][2] - 1) < k) continue;
if (intersection(x - dp[x][y][1] + 1, x + dp[x][y][3] - 1, nx - dp[nx][ny][1] + 1, nx + dp[nx][ny][3] - 1) < l) continue;
dfs(nx, ny);
}
}
int main(){
cin >> m >> n >> k >> l;
cin >> sx >> sx >> sy >> garbage;
for (int i = 0; i < n; i ++)
for (int j = 0; j < m; j ++)
cin >> mat[i][j];
for (int i = 0; i < n; i ++){
for (int j = 0; j < m; j ++){
if (!valid(i, j)) continue;
if (!valid(i, j - 1)) dp[i][j][0] = 1;
else dp[i][j][0] = dp[i][j - 1][0] + 1;
if (!valid(i - 1, j)) dp[i][j][1] = 1;
else dp[i][j][1] = dp[i - 1][j][1] + 1;
}
}
for (int j = m - 1; j >= 0; j --){
for (int i = n - 1; i >= 0; i --){
if (!valid(i, j)) continue;
if (!valid(i, j + 1)) dp[i][j][2] = 1;
else dp[i][j][2] = dp[i][j + 1][2] + 1;
if (!valid(i + 1, j)) dp[i][j][3] = 1;
else dp[i][j][3] = dp[i + 1][j][3] + 1;
}
}
dfs(sx, sy);
cout << (yes ? "YES" : "NO") << endl;
}
# | 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... |