This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define MAXN 1507
using namespace std;
bool b[MAXN][MAXN],vi[MAXN][MAXN];
int rb[MAXN][MAXN],ub[MAXN][MAXN],db[MAXN][MAXN],lb[MAXN][MAXN],k,l;
void dfs(int x,int y)
{
vi[x][y]=true;
if(!b[x][y+1] && !vi[x][y+1]) {
int left=max(lb[x][y],lb[x][y+1]),right=min(rb[x][y],rb[x][y+1]);
if(right-left>k) dfs(x,y+1);
}
if(!b[x][y-1] && !vi[x][y-1]) {
int left=max(lb[x][y],lb[x][y-1]),right=min(rb[x][y],rb[x][y-1]);
if(right-left>k) dfs(x,y-1);
}
if(!b[x+1][y] && !vi[x+1][y]) {
int up=max(ub[x][y],ub[x+1][y]),down=min(db[x][y],db[x+1][y]);
if(down-up>l) dfs(x+1,y);
}
if(!b[y][x-1] && !vi[y][x-1]) {
int up=max(ub[x][y],ub[x-1][y]),down=min(db[x][y],db[x-1][y]);
if(down-up>l) dfs(x-1,y);
}
}
int main(){
int w,h,xh,yh,xv,yv;
cin>>w>>h>>l>>k>>xh>>yh>>xv>>yv;
int xt,yt,xs=xv+1,ys=yh+1;
for(int i=0;i<h;i++) {
string s;
cin>>s;
for(int j=0;j<w;j++){
if(s[j]=='*'){
yt=i+1;
xt=j+1;
}
if(s[j]=='X') b[j+1][i+1]=true;
}
}
for(int i=1;i<=h;i++) b[0][i]=b[w+1][i]=true;
for(int i=1;i<=w;i++) b[i][0]=b[i][h+1]=true;
for(int i=1;i<=h;i++) {
int ls;
for(int j=0;j<=w;j++) {
if(b[j][i]) ls=j;
lb[j][i]=ls;
}
for(int j=w+1;j>0;j--) {
if(b[j][i]) ls=j;
rb[j][i]=ls;
}
}
for(int i=1;i<=w;i++) {
int ls;
for(int j=0;j<=h;j++) {
if(b[i][j]) ls=j;
ub[i][j]=ls;
}
for(int j=h+1;j>0;j--) {
if(b[i][j]) ls=j;
db[i][j]=ls;
}
}
dfs(xs,ys);
if(vi[xt][yt]) cout<<"YES";
else cout<<"NO";
}
Compilation message (stderr)
Main.cpp: In function 'int main()':
Main.cpp:67:17: warning: 'yt' may be used uninitialized in this function [-Wmaybe-uninitialized]
67 | if(vi[xt][yt]) cout<<"YES";
| ~~~~~~~~~^
Main.cpp:67:17: warning: 'xt' may be used uninitialized in this function [-Wmaybe-uninitialized]
Main.cpp:59:21: warning: 'ls' may be used uninitialized in this function [-Wmaybe-uninitialized]
59 | ub[i][j]=ls;
| ~~~~~~~~^~~
Main.cpp:48:21: warning: 'ls' may be used uninitialized in this function [-Wmaybe-uninitialized]
48 | lb[j][i]=ls;
| ~~~~~~~~^~~
# | 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... |