#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define vi vector<int>
#define si set<int>
#define usi unordered_set<int>
#define sll set<ll>
#define usll unordered_set<ll>
#define vb vector<bool>
#define vll vector<ll>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vvi vector<vector<int>>
#define vvll vector<vector<ll>>
// xh, yh, xv, yv
bool visited[90][90][90][90];
void solve() {
int W, H, K, L;
cin >> W >> H >> K >> L;
int xh, yh, xv, yv, gx, gy;
cin >> yh >> xh >> yv >> xv;
vector<string> grid(H);
for (int i = 0; i < H; i++)
cin >> grid[i];
vector<vi> psum(H + 1, vi(W + 1));
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
if (grid[i][j] == '*') {
gx = i;
gy = j;
}
psum[i + 1][j + 1] =
(grid[i][j] == 'X') + psum[i][j + 1] + psum[i + 1][j] - psum[i][j];
}
}
vll dx{-1, 0, 1, 0};
vll dy{0, 1, 0, -1};
queue<tuple<int, int, int, int>> q;
q.push(make_tuple(xh, yh, xv, yv));
// x1, y1 are top left, x2, y2 are bottom right
// all values are 0 indexed
auto queryRegion = [&](ll x1, ll y1, ll x2, ll y2) {
return psum[x2 + 1][y2 + 1] - psum[x1][y2 + 1] - psum[x2 + 1][y1] +
psum[x1][y1];
};
auto checkCoord = [&](ll x, ll y) {
return (x >= 0 && x < H && y >= 0 && y < W);
};
// x1, y1 are horizontal piece; x2, y2 are vertical piece
auto check = [&](ll x1, ll y1, ll x2, ll y2) {
bool works = true;
works &= checkCoord(x1, y1);
works &= checkCoord(x1, y1 + K - 1);
works &= checkCoord(x2, y2);
works &= checkCoord(x2 + L - 1, y2);
if (!works)
return false;
// check y coordinate intersection
works &= !(y1 > y2 || y1 + K - 1 < y2);
// check x coordinate intersection
works &= !(x2 > x1 || x2 + L - 1 < x1);
if (!works)
return false;
// check no obstacle intersection
works &= (queryRegion(x1, y1, x1, y1 + K - 1) == 0);
works &= (queryRegion(x2, y2, x2 + L - 1, y2) == 0);
return works;
};
while (!q.empty()) {
int cxh, cyh, cxv, cyv;
tie(cxh, cyh, cxv, cyv) = q.front();
/*cout << cxh << " " << cyh << " " << cxv << " " << cyv << endl;*/
q.pop();
if (cxh == gx && cyv == gy) {
cout << "YES\n";
return;
}
for (int i = 0; i < 4; i++) {
int nxh = cxh + dx[i];
int nyh = cyh + dy[i];
if (check(nxh, nyh, cxv, cyv) && !visited[nxh][nyh][cxv][cyv]) {
visited[nxh][nyh][cxv][cyv] = true;
q.push(make_tuple(nxh, nyh, cxv, cyv));
}
}
for (int i = 0; i < 4; i++) {
int nxv = cxv + dx[i];
int nyv = cyv + dy[i];
if (check(cxh, cyh, nxv, nyv) && !visited[cxh][cyh][nxv][nyv]) {
visited[cxh][cyh][nxv][nyv] = true;
q.push(make_tuple(cxh, cyh, nxv, nyv));
}
}
}
cout << "NO\n";
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
solve();
}
# | 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... |