답안 #1045744

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1045744 2024-08-06T07:20:31 Z gagik_2007 Toy (CEOI24_toy) C++17
0 / 100
13 ms 20980 KB
#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=307;
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++){
            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++){
            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++){
            // 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++){
            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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2652 KB Output is correct
4 Correct 1 ms 2904 KB Output is correct
5 Incorrect 1 ms 2908 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2652 KB Output is correct
4 Correct 1 ms 2904 KB Output is correct
5 Incorrect 1 ms 2908 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 1 ms 3324 KB Output is correct
4 Correct 8 ms 14036 KB Output is correct
5 Correct 7 ms 10784 KB Output is correct
6 Correct 2 ms 3420 KB Output is correct
7 Correct 7 ms 9564 KB Output is correct
8 Correct 10 ms 7768 KB Output is correct
9 Correct 1 ms 2652 KB Output is correct
10 Correct 1 ms 2652 KB Output is correct
11 Correct 1 ms 2652 KB Output is correct
12 Correct 1 ms 2652 KB Output is correct
13 Correct 1 ms 2652 KB Output is correct
14 Correct 2 ms 2652 KB Output is correct
15 Correct 11 ms 19292 KB Output is correct
16 Correct 9 ms 15964 KB Output is correct
17 Correct 10 ms 16988 KB Output is correct
18 Incorrect 13 ms 20980 KB Output isn't correct
19 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2652 KB Output is correct
4 Correct 1 ms 2904 KB Output is correct
5 Incorrect 1 ms 2908 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2652 KB Output is correct
4 Correct 1 ms 2904 KB Output is correct
5 Incorrect 1 ms 2908 KB Output isn't correct
6 Halted 0 ms 0 KB -