1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
| #include <cstdio> #include <algorithm> #include <queue> #include <bitset>
using namespace std;
bitset<1505> vis[1505]; char mp[1505][1505]; unsigned lt[1505][1505], rt[1505][1505], ut[1505][1505], dt[1505][1505];
int main() { unsigned m, n, a, b; scanf("%u%u%u%u", &m, &n, &a, &b); unsigned sx, sy; scanf("%*u%u%u%*u", &sx, &sy); sx++; sy++; for(unsigned i=1;i<=n;i++) { while(getchar() != '\n'); fread(mp[i] + 1, 1, m, stdin); } unsigned tx = 0, ty = 0; for(unsigned i=1;i<=n;i++) { for(unsigned j=1;j<=m;j++) { if(mp[i][j] == '*') { mp[i][j] = '.'; tx = i; ty = j; } lt[i][j] = (mp[i][j] == '.' ? lt[i][j-1] + 1 : 0); ut[i][j] = (mp[i][j] == '.' ? ut[i-1][j] + 1 : 0); } } for(unsigned i=n;i>=1;i--) { for(unsigned j=m;j>=1;j--) { rt[i][j] = (mp[i][j] == '.' ? rt[i][j+1] + 1 : 0); dt[i][j] = (mp[i][j] == '.' ? dt[i+1][j] + 1 : 0); } } queue<pair<unsigned, unsigned>> q; q.push({sx, sy}); mp[sx][sy] = true; while(!q.empty()) { auto [x, y] = q.front(); q.pop(); if(x == tx && y == ty) { printf("YES\n"); return 0; } for(unsigned dx = -1; dx != 3; dx += 2) { unsigned vx = x + dx; if(vx < 1 || vx > n) continue; if(mp[vx][y] == 'X') continue; if(vis[vx][y]) continue; unsigned l1 = y - lt[vx][y] + 1, r1 = y + rt[vx][y] - 1; unsigned l2 = y - lt[x][y] + 1, r2 = y + rt[x][y] - 1; if(min(r1, r2) - max(l1, l2) + 1 >= a) { vis[vx][y] = true; q.push({vx, y}); } } for(unsigned dy = -1; dy != 3; dy += 2) { unsigned vy = y + dy; if(vy < 1 || vy > m) continue; if(mp[x][vy] == 'X') continue; if(vis[x][vy]) continue; unsigned l1 = x - ut[x][vy] + 1, r1 = x + dt[x][vy] - 1; unsigned l2 = x - ut[x][y] + 1, r2 = x + dt[x][y] - 1; if(min(r1, r2) - max(l1, l2) + 1 >= b) { vis[x][vy] = true; q.push({x, vy}); } } } printf("NO\n"); return 0; }
|