#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MAX_N = 1500;
int k, l, h, w;
string grid[MAX_N];
bool intersect[MAX_N][MAX_N];
int up[MAX_N][MAX_N], down[MAX_N][MAX_N], lft[MAX_N][MAX_N], rght[MAX_N][MAX_N];
void func(int x, int y) {
if(x+1 != h && grid[x+1][y] != 'X' && !intersect[x+1][y]) {
int min_up = min(up[x+1][y], up[x][y]), min_down = min(down[x+1][y], down[x][y]), sum = min_up + min_down - 1;
if(sum >= l) {
intersect[x+1][y] = 1;
func(x+1, y);
}
}
if(x && grid[x-1][y] != 'X' && !intersect[x-1][y]) {
int min_up = min(up[x-1][y], up[x][y]), min_down = min(down[x-1][y], down[x][y]), sum = min_up + min_down - 1;
if(sum >= l) {
intersect[x-1][y] = 1;
func(x-1, y);
}
}
if(y+1 != w && grid[x][y+1] != 'X' && !intersect[x][y+1]) {
int min_left = min(lft[x][y+1], lft[x][y]), min_right = min(rght[x][y+1], rght[x][y]), sum = min_left + min_right - 1;
if(sum >= k) {
intersect[x][y+1] = 1;
func(x, y+1);
}
}
if(y && grid[x][y-1] != 'X' && !intersect[x][y-1]) {
int min_left = min(lft[x][y-1], lft[x][y]), min_right = min(rght[x][y-1], rght[x][y]), sum = min_left + min_right - 1;
if(sum >= k) {
intersect[x][y-1] = 1;
func(x, y-1);
}
}
}
void solve() {
int x1, y1, x2, y2;
cin >> w >> h >> k >> l >> x1 >> y1 >> x2 >> y2;
int ex, ey;
for(int i=0; i<h; ++i) {
cin >> grid[i];
for(int j=0; j<w; ++j) {
if(grid[i][j] == '*') ex = i, ey = j;
}
}
intersect[y1][x2] = 1;
for(int i=0; i<h; ++i) {
up[i][0] = (grid[i][0] == 'X' ? 0 : 1);
down[i][w-1] = (grid[i][w-1] == 'X' ? 0 : 1);
for(int j=1; j<w; ++j) up[i][j] = (grid[i][j] == 'X' ? 0 : up[i][j-1] + 1);
for(int j=w-2; j>=0; --j) down[i][j] = (grid[i][j] == 'X' ? 0 : down[i][j+1] + 1);
}
for(int i=0; i<w; ++i) {
lft[0][i] = (grid[0][i] == 'X' ? 0 : 1);
rght[h-1][i] = (grid[h-1][i] == 'X' ? 0 : 1);
for(int j=1; j<h; ++j) lft[j][i] = (grid[j][i] == 'X' ? 0 : lft[j-1][i] + 1);
for(int j=h-2; j>=0; --j) rght[j][i] = (grid[j][i] == 'X' ? 0 : rght[j+1][i] + 1);
}
func(y1, x2);
cout << (intersect[ex][ey] ? "YES" : "NO") << endl;
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int t = 1;
while(t--) solve();
}
Compilation message
Main.cpp: In function 'void solve()':
Main.cpp:69:29: warning: 'ex' may be used uninitialized in this function [-Wmaybe-uninitialized]
69 | cout << (intersect[ex][ey] ? "YES" : "NO") << endl;
| ~~~~~~~~~~~~~~~~^
Main.cpp:69:29: warning: 'ey' may be used uninitialized in this function [-Wmaybe-uninitialized]
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
8536 KB |
Output is correct |
2 |
Correct |
1 ms |
8540 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
8536 KB |
Output is correct |
2 |
Correct |
1 ms |
8540 KB |
Output is correct |
3 |
Incorrect |
1 ms |
10588 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
8536 KB |
Output is correct |
2 |
Correct |
1 ms |
8540 KB |
Output is correct |
3 |
Incorrect |
1 ms |
10588 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
8536 KB |
Output is correct |
2 |
Correct |
1 ms |
8540 KB |
Output is correct |
3 |
Correct |
1 ms |
11100 KB |
Output is correct |
4 |
Correct |
7 ms |
29288 KB |
Output is correct |
5 |
Correct |
6 ms |
27264 KB |
Output is correct |
6 |
Correct |
2 ms |
13404 KB |
Output is correct |
7 |
Correct |
5 ms |
25608 KB |
Output is correct |
8 |
Correct |
7 ms |
26716 KB |
Output is correct |
9 |
Correct |
2 ms |
14924 KB |
Output is correct |
10 |
Correct |
4 ms |
23388 KB |
Output is correct |
11 |
Correct |
3 ms |
23132 KB |
Output is correct |
12 |
Correct |
2 ms |
21084 KB |
Output is correct |
13 |
Correct |
4 ms |
23128 KB |
Output is correct |
14 |
Correct |
4 ms |
23132 KB |
Output is correct |
15 |
Correct |
9 ms |
31664 KB |
Output is correct |
16 |
Correct |
7 ms |
30812 KB |
Output is correct |
17 |
Correct |
8 ms |
30556 KB |
Output is correct |
18 |
Correct |
9 ms |
33116 KB |
Output is correct |
19 |
Correct |
9 ms |
33156 KB |
Output is correct |
20 |
Correct |
10 ms |
33060 KB |
Output is correct |
21 |
Correct |
9 ms |
33116 KB |
Output is correct |
22 |
Correct |
9 ms |
33176 KB |
Output is correct |
23 |
Correct |
8 ms |
33116 KB |
Output is correct |
24 |
Correct |
9 ms |
33188 KB |
Output is correct |
25 |
Correct |
9 ms |
33132 KB |
Output is correct |
26 |
Correct |
8 ms |
29288 KB |
Output is correct |
27 |
Correct |
6 ms |
29276 KB |
Output is correct |
28 |
Correct |
8 ms |
29296 KB |
Output is correct |
29 |
Correct |
7 ms |
29276 KB |
Output is correct |
30 |
Correct |
9 ms |
32604 KB |
Output is correct |
31 |
Correct |
8 ms |
32348 KB |
Output is correct |
32 |
Correct |
10 ms |
32860 KB |
Output is correct |
33 |
Correct |
8 ms |
32208 KB |
Output is correct |
34 |
Correct |
9 ms |
32092 KB |
Output is correct |
35 |
Correct |
10 ms |
32092 KB |
Output is correct |
36 |
Correct |
3 ms |
23132 KB |
Output is correct |
37 |
Correct |
5 ms |
26376 KB |
Output is correct |
38 |
Correct |
4 ms |
26204 KB |
Output is correct |
39 |
Correct |
4 ms |
26204 KB |
Output is correct |
40 |
Correct |
6 ms |
26456 KB |
Output is correct |
41 |
Correct |
4 ms |
26204 KB |
Output is correct |
42 |
Correct |
7 ms |
29788 KB |
Output is correct |
43 |
Correct |
7 ms |
30496 KB |
Output is correct |
44 |
Correct |
7 ms |
28764 KB |
Output is correct |
45 |
Correct |
8 ms |
30924 KB |
Output is correct |
46 |
Correct |
3 ms |
23132 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
8536 KB |
Output is correct |
2 |
Correct |
1 ms |
8540 KB |
Output is correct |
3 |
Incorrect |
1 ms |
10588 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
8536 KB |
Output is correct |
2 |
Correct |
1 ms |
8540 KB |
Output is correct |
3 |
Incorrect |
1 ms |
10588 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |