#include <bits/stdc++.h>
using namespace std;
const int nx=1505;
int n, k, l, r, c, dpl[nx][nx], dpr[nx][nx], dpup[nx][nx], dpdn[nx][nx], a, b, w, h, x, y, tmp;
pair<int, int> dsu[nx][nx];
char mp[nx][nx];
pair<int, int> find(pair<int, int> loc)
{
if (dsu[loc.first][loc.second]==loc) return loc;
return dsu[loc.first][loc.second]=find(dsu[loc.first][loc.second]);
}
int main()
{
cin.tie(NULL)->sync_with_stdio(false);
cin>>c>>r>>w>>h;
cin>>tmp>>x>>tmp>>y;
x++, y++;
for (int i=1; i<=r; i++) for (int j=1; j<=c; j++) cin>>mp[i][j], dsu[i][j]={i, j};
for (int i=1; i<=r; i++) for (int j=1; j<=c; j++) if (mp[i][j]=='*') a=i, b=j;
//cout<<"debug "<<x<<' '<<y<<' '<<a<<' '<<b<<'\n';
for (int i=1; i<=r; i++)
{
for (int j=1; j<=c; j++)
{
if (mp[i][j]=='X') continue;
if (j==1||mp[i][j-1]=='X') dpl[i][j]=j;
else dpl[i][j]=dpl[i][j-1];
}
}
for (int i=1; i<=r; i++)
{
for (int j=c; j>=1; j--)
{
if (mp[i][j]=='X') continue;
if (j==c||mp[i][j+1]=='X') dpr[i][j]=j;
else dpr[i][j]=dpr[i][j+1];
}
}
for (int j=1; j<=c; j++)
{
for (int i=1; i<=r; i++)
{
if (mp[i][j]=='X') continue;
if (i==1||mp[i-1][j]=='X') dpup[i][j]=i;
else dpup[i][j]=dpup[i-1][j];
}
}
for (int j=1; j<=c; j++)
{
for (int i=r; i>=1; i--)
{
if (mp[i][j]=='X') continue;
if (i==r||mp[i+1][j]=='X') dpdn[i][j]=i;
else dpdn[i][j]=dpdn[i+1][j];
}
}
for (int i=1; i<=r; i++)
{
for (int j=1; j<c; j++)
{
if (mp[i][j]=='X'||mp[i][j+1]=='X'||dpdn[i][j]-dpup[i][j]+1<h||dpdn[i][j+1]-dpup[i][j+1]+1<h) continue;
int st=min({dpdn[i][j], dpdn[i][j+1], i+h-1});
if (st-h+1>=dpup[i][j]&&st-h+1>=dpup[i][j+1])
{
auto pu=find({i, j}), pv=find({i, j+1});
dsu[pu.first][pu.second]=pv;
}
}
}
for (int i=1; i<r; i++)
{
for (int j=1; j<=c; j++)
{
if (mp[i][j]=='X'||mp[i+1][j]=='X'||dpr[i][j]-dpl[i][j]+1<w||dpr[i+1][j]-dpl[i+1][j]<w) continue;
int st=min({dpr[i][j], dpr[i+1][j], j+w-1});
if (st-w+1>=dpl[i][j]&&st-w+1>=dpl[i+1][j])
{
auto pu=find({i, j}), pv=find({i+1, j});
dsu[pu.first][pu.second]=pv;
}
}
}
if (find({x, y})==find({a, b})) cout<<"YES";
else cout<<"NO";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6488 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6488 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
12632 KB |
Output is correct |
4 |
Correct |
2 ms |
14684 KB |
Output is correct |
5 |
Correct |
2 ms |
14684 KB |
Output is correct |
6 |
Incorrect |
1 ms |
14684 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6488 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
12632 KB |
Output is correct |
4 |
Correct |
2 ms |
14684 KB |
Output is correct |
5 |
Correct |
2 ms |
14684 KB |
Output is correct |
6 |
Incorrect |
1 ms |
14684 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6488 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
2 ms |
8792 KB |
Output is correct |
4 |
Correct |
8 ms |
9052 KB |
Output is correct |
5 |
Correct |
5 ms |
23128 KB |
Output is correct |
6 |
Correct |
3 ms |
14940 KB |
Output is correct |
7 |
Correct |
7 ms |
9004 KB |
Output is correct |
8 |
Correct |
9 ms |
16988 KB |
Output is correct |
9 |
Correct |
2 ms |
3416 KB |
Output is correct |
10 |
Correct |
7 ms |
23132 KB |
Output is correct |
11 |
Correct |
4 ms |
23132 KB |
Output is correct |
12 |
Correct |
3 ms |
21084 KB |
Output is correct |
13 |
Correct |
5 ms |
23308 KB |
Output is correct |
14 |
Correct |
5 ms |
23132 KB |
Output is correct |
15 |
Correct |
7 ms |
23296 KB |
Output is correct |
16 |
Correct |
6 ms |
23308 KB |
Output is correct |
17 |
Correct |
6 ms |
12892 KB |
Output is correct |
18 |
Correct |
8 ms |
9052 KB |
Output is correct |
19 |
Correct |
7 ms |
9048 KB |
Output is correct |
20 |
Correct |
8 ms |
9132 KB |
Output is correct |
21 |
Correct |
6 ms |
23132 KB |
Output is correct |
22 |
Correct |
5 ms |
23132 KB |
Output is correct |
23 |
Correct |
6 ms |
23132 KB |
Output is correct |
24 |
Correct |
5 ms |
23132 KB |
Output is correct |
25 |
Correct |
8 ms |
9052 KB |
Output is correct |
26 |
Correct |
7 ms |
23128 KB |
Output is correct |
27 |
Correct |
8 ms |
14428 KB |
Output is correct |
28 |
Correct |
6 ms |
9052 KB |
Output is correct |
29 |
Correct |
9 ms |
9140 KB |
Output is correct |
30 |
Correct |
6 ms |
8820 KB |
Output is correct |
31 |
Correct |
6 ms |
23128 KB |
Output is correct |
32 |
Correct |
5 ms |
23132 KB |
Output is correct |
33 |
Correct |
5 ms |
23132 KB |
Output is correct |
34 |
Correct |
5 ms |
23132 KB |
Output is correct |
35 |
Correct |
5 ms |
23132 KB |
Output is correct |
36 |
Correct |
3 ms |
23168 KB |
Output is correct |
37 |
Correct |
7 ms |
10076 KB |
Output is correct |
38 |
Correct |
9 ms |
8920 KB |
Output is correct |
39 |
Correct |
6 ms |
17500 KB |
Output is correct |
40 |
Correct |
5 ms |
23132 KB |
Output is correct |
41 |
Correct |
6 ms |
23132 KB |
Output is correct |
42 |
Correct |
5 ms |
23128 KB |
Output is correct |
43 |
Correct |
7 ms |
23128 KB |
Output is correct |
44 |
Correct |
7 ms |
23132 KB |
Output is correct |
45 |
Correct |
5 ms |
23316 KB |
Output is correct |
46 |
Correct |
3 ms |
23208 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6488 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
12632 KB |
Output is correct |
4 |
Correct |
2 ms |
14684 KB |
Output is correct |
5 |
Correct |
2 ms |
14684 KB |
Output is correct |
6 |
Incorrect |
1 ms |
14684 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6488 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
12632 KB |
Output is correct |
4 |
Correct |
2 ms |
14684 KB |
Output is correct |
5 |
Correct |
2 ms |
14684 KB |
Output is correct |
6 |
Incorrect |
1 ms |
14684 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |