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>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define ff first
#define ss second
ll ttt;
const ll INF=1e18;
const ll MOD=1e9+7;
const ll N=2007;
ll n,m,k;
int h, v;
bool dp[N][N];
bool vis[N][N];
bool d[N][N];
int pf[2*N][2*N];
int colpf[2*N][2*N];
int tgi,tgj;
int getPf(int i, int j1, int j2){
if(j1==0)return pf[i][j2];
return pf[i][j2]-pf[i][j1-1];
}
int getColPf(int j, int i1, int i2){
if(i1==0)return colpf[j][i2];
return colpf[j][i2]-colpf[j][i1-1];
}
void recurs(int i, int j){
if(vis[i][j])return;
vis[i][j]=true;
if(!dp[i][j])return;
// cout<<i<<" "<<j<<endl;
//left
if(j>0&&!d[i][j-1]){
for(int vi=max(0,i-v+1);vi<=i&&vi+v<=n;vi++){
if(getColPf(j,vi,vi+v-1)==0 &&
getColPf(j-1,vi,vi+v-1)==0){
dp[i][j-1]=true;
recurs(i,j-1);
break;
}
}
}
//right
if(j<m-1&&!d[i][j+1]){
for(int vi=max(0,i-v+1);vi<=i&&vi+v<=n;vi++){
if(getColPf(j,vi,vi+v-1)==0 &&
getColPf(j+1,vi,vi+v-1)==0){
dp[i][j+1]=true;
recurs(i,j+1);
break;
}
}
}
//up
if(i>0&&!d[i-1][j]){
// cout<<"OK "<<i<<" "<<j<<endl;
for(int hj=max(0,j-h+1);hj<=j&&hj+h<=m;hj++){
// cout<<hj<<": "<<getPf(i,hj,hj+h-1)<<", "<<getPf(i-1,hj,hj+h-1)<<endl;
if(getPf(i,hj,hj+h-1)==0 &&
getPf(i-1,hj,hj+h-1)==0){
dp[i-1][j]=true;
recurs(i-1,j);
break;
}
}
}
//down
if(i<n-1&&!d[i+1][j]){
for(int hj=max(0,j-h+1);hj<=j&&hj+h<=m;hj++){
if(getPf(i,hj,hj+h-1)==0 &&
getPf(i+1,hj,hj+h-1)==0){
dp[i+1][j]=true;
recurs(i+1,j);
break;
}
}
}
}
void calculatePfs(){
for(int i=0;i<n;i++){
pf[i][0]=d[i][0];
for(int j=1;j<2*m;j++){
pf[i][j]=pf[i][j-1]+d[i][j];
}
}
for(int j=0;j<m;j++){
colpf[j][0]=d[0][j];
for(int i=1;i<2*n;i++){
colpf[j][i]=colpf[j][i-1]+d[i][j];
}
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
// freopen("Dinput.txt","r",stdin);
// freopen("Doutput.txt","w",stdout);
cin>>m>>n;
cin>>h>>v;
int i1,i2,j1,j2;
cin>>j1>>i1>>j2>>i2;
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
char c;
cin>>c;
// cout<<c;
if(c=='X'){
d[i][j]=true;
}
if(c=='*'){
tgi=i;
tgj=j;
// cout<<i<<" "<<j<<endl;
}
}
// cout<<endl;
}
calculatePfs();
int ii=i1;
int jj=j2;
dp[ii][jj]=true;
recurs(ii,jj);
if(dp[tgi][tgj]){
// cout<<tgi<<" "<<tgj<<endl;
// cout<<lh<<" "<<lv<<endl;
cout<<"YES"<<endl;
return 0;
}
cout<<"NO"<<endl;
return 0;
}
# | 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... |