답안 #1045689

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1045689 2024-08-06T06:58:43 Z gagik_2007 Toy (CEOI24_toy) C++17
35 / 100
762 ms 765016 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=93;
ll n,m,k;
int h, v;
bool dp[N][N][N][N];
bool vis[N][N][N][N];
bool d[N][N];
int pf[N][N];
int colpf[N][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, int lh, int lv){
    if(vis[i][j][lh][lv])return;
    vis[i][j][lh][lv]=true;
    if(!dp[i][j][lh][lv])return;
    // cout<<i<<" "<<j<<" "<<lh<<" "<<lv<<endl;

    int hi=i,hj=j-lh;
    int vi=i-lv,vj=j;

    // H movement
    //up
    if(i>0&&lv>0&&getPf(hi-1,hj,hj+h-1)==0){
        dp[i-1][j][lh][lv-1]=true;
        recurs(i-1,j,lh,lv-1);
    }
    //down
    if(i<n-1&&lv<v-1&&getPf(hi+1,hj,hj+h-1)==0){
        dp[i+1][j][lh][lv+1]=true;
        recurs(i+1,j,lh,lv+1);
    }
    //left
    if(hj>0&&lh<h-1&&!d[i][hj-1]){
        dp[i][j][lh+1][lv]=true;
        recurs(i,j,lh+1,lv);
    }
    //right
    if(hj+h<m&&lh>0&&!d[i][hj+h]){
        dp[i][j][lh-1][lv]=true;
        recurs(i,j,lh-1,lv);
    }

    // V movement
    //up
    if(vi>0&&lv<v-1&&!d[vi-1][j]){
        dp[i][j][lh][lv+1]=true;
        recurs(i,j,lh,lv+1);
    }
    //down
    // cout<<vi+v<<" < "<<n<<" && "<<lv<<" > 0 && !"<<d[vi+v][j]<<endl;
    if(vi+v<n&&lv>0&&!d[vi+v][j]){
        dp[i][j][lh][lv-1]=true;
        recurs(i,j,lh,lv-1);
    }
    //left
    if(j>0&&lh>0&&getColPf(j-1,vi,vi+v-1)==0){
        dp[i][j-1][lh-1][lv]=true;
        recurs(i,j-1,lh-1,lv);
    }
    //right
    if(j<m-1&&lh<h-1&&getColPf(j+1,vi,vi+v-1)==0){
        dp[i][j+1][lh+1][lv]=true;
        recurs(i,j+1,lh+1,lv);
    }
}

void calculatePfs(){
    for(int i=0;i<n;i++){
        pf[i][0]=d[i][0];
        for(int j=1;j<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<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;
    int lh=jj-j1;
    int lv=ii-i2;
    dp[ii][jj][lh][lv]=true;
    recurs(ii,jj,lh,lv);
    for(lh=0;lh<h;lh++){
        for(lv=0;lv<v;lv++){
            if(dp[tgi][tgj][lh][lv]){
                // cout<<tgi<<" "<<tgj<<endl;
                // cout<<lh<<" "<<lv<<endl;
                cout<<"YES"<<endl;
                return 0;
            }
        }
    }
    cout<<"NO"<<endl;
    return 0;
}

Compilation message

Main.cpp: In function 'void recurs(int, int, int, int)':
Main.cpp:42:17: warning: unused variable 'vj' [-Wunused-variable]
   42 |     int vi=i-lv,vj=j;
      |                 ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 3 ms 18012 KB Output is correct
4 Correct 45 ms 100236 KB Output is correct
5 Correct 3 ms 30556 KB Output is correct
6 Correct 3 ms 35932 KB Output is correct
7 Correct 2 ms 18268 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 0 ms 2396 KB Output is correct
12 Correct 0 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 0 ms 2396 KB Output is correct
15 Correct 54 ms 110160 KB Output is correct
16 Correct 58 ms 94764 KB Output is correct
17 Correct 45 ms 95316 KB Output is correct
18 Correct 62 ms 117052 KB Output is correct
19 Correct 69 ms 121684 KB Output is correct
20 Correct 58 ms 112132 KB Output is correct
21 Correct 56 ms 110676 KB Output is correct
22 Correct 77 ms 116656 KB Output is correct
23 Correct 90 ms 112476 KB Output is correct
24 Correct 27 ms 76112 KB Output is correct
25 Correct 26 ms 76120 KB Output is correct
26 Correct 21 ms 67628 KB Output is correct
27 Correct 21 ms 68444 KB Output is correct
28 Correct 23 ms 67164 KB Output is correct
29 Correct 17 ms 62828 KB Output is correct
30 Correct 23 ms 66516 KB Output is correct
31 Correct 25 ms 69020 KB Output is correct
32 Correct 15 ms 59304 KB Output is correct
33 Correct 17 ms 63580 KB Output is correct
34 Correct 20 ms 69208 KB Output is correct
35 Correct 20 ms 65624 KB Output is correct
36 Correct 1 ms 5208 KB Output is correct
37 Correct 6 ms 32604 KB Output is correct
38 Correct 11 ms 35244 KB Output is correct
39 Correct 7 ms 33112 KB Output is correct
40 Correct 7 ms 34908 KB Output is correct
41 Correct 8 ms 35416 KB Output is correct
42 Correct 7 ms 52060 KB Output is correct
43 Correct 6 ms 51804 KB Output is correct
44 Correct 6 ms 51804 KB Output is correct
45 Correct 8 ms 51804 KB Output is correct
46 Correct 0 ms 2476 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 3 ms 18012 KB Output is correct
4 Correct 45 ms 100236 KB Output is correct
5 Correct 3 ms 30556 KB Output is correct
6 Correct 3 ms 35932 KB Output is correct
7 Correct 2 ms 18268 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 0 ms 2396 KB Output is correct
12 Correct 0 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 0 ms 2396 KB Output is correct
15 Correct 54 ms 110160 KB Output is correct
16 Correct 58 ms 94764 KB Output is correct
17 Correct 45 ms 95316 KB Output is correct
18 Correct 62 ms 117052 KB Output is correct
19 Correct 69 ms 121684 KB Output is correct
20 Correct 58 ms 112132 KB Output is correct
21 Correct 56 ms 110676 KB Output is correct
22 Correct 77 ms 116656 KB Output is correct
23 Correct 90 ms 112476 KB Output is correct
24 Correct 27 ms 76112 KB Output is correct
25 Correct 26 ms 76120 KB Output is correct
26 Correct 21 ms 67628 KB Output is correct
27 Correct 21 ms 68444 KB Output is correct
28 Correct 23 ms 67164 KB Output is correct
29 Correct 17 ms 62828 KB Output is correct
30 Correct 23 ms 66516 KB Output is correct
31 Correct 25 ms 69020 KB Output is correct
32 Correct 15 ms 59304 KB Output is correct
33 Correct 17 ms 63580 KB Output is correct
34 Correct 20 ms 69208 KB Output is correct
35 Correct 20 ms 65624 KB Output is correct
36 Correct 1 ms 5208 KB Output is correct
37 Correct 6 ms 32604 KB Output is correct
38 Correct 11 ms 35244 KB Output is correct
39 Correct 7 ms 33112 KB Output is correct
40 Correct 7 ms 34908 KB Output is correct
41 Correct 8 ms 35416 KB Output is correct
42 Correct 7 ms 52060 KB Output is correct
43 Correct 6 ms 51804 KB Output is correct
44 Correct 6 ms 51804 KB Output is correct
45 Correct 8 ms 51804 KB Output is correct
46 Correct 0 ms 2476 KB Output is correct
47 Correct 14 ms 38748 KB Output is correct
48 Correct 8 ms 14592 KB Output is correct
49 Correct 4 ms 26768 KB Output is correct
50 Correct 1 ms 4952 KB Output is correct
51 Correct 20 ms 36696 KB Output is correct
52 Correct 0 ms 2396 KB Output is correct
53 Correct 0 ms 4444 KB Output is correct
54 Correct 1 ms 2396 KB Output is correct
55 Correct 0 ms 2396 KB Output is correct
56 Correct 1 ms 2396 KB Output is correct
57 Correct 0 ms 2496 KB Output is correct
58 Correct 0 ms 2396 KB Output is correct
59 Correct 553 ms 627700 KB Output is correct
60 Correct 486 ms 621120 KB Output is correct
61 Correct 602 ms 597704 KB Output is correct
62 Correct 716 ms 765016 KB Output is correct
63 Correct 762 ms 701104 KB Output is correct
64 Correct 621 ms 603292 KB Output is correct
65 Correct 687 ms 738644 KB Output is correct
66 Correct 662 ms 674372 KB Output is correct
67 Correct 656 ms 605780 KB Output is correct
68 Correct 356 ms 407560 KB Output is correct
69 Correct 303 ms 355964 KB Output is correct
70 Correct 224 ms 289844 KB Output is correct
71 Correct 213 ms 271232 KB Output is correct
72 Correct 206 ms 247488 KB Output is correct
73 Correct 214 ms 230564 KB Output is correct
74 Correct 93 ms 174672 KB Output is correct
75 Correct 113 ms 169924 KB Output is correct
76 Correct 121 ms 186028 KB Output is correct
77 Correct 64 ms 145744 KB Output is correct
78 Correct 92 ms 179792 KB Output is correct
79 Correct 49 ms 141488 KB Output is correct
80 Correct 2 ms 5468 KB Output is correct
81 Correct 66 ms 101320 KB Output is correct
82 Correct 55 ms 104016 KB Output is correct
83 Correct 48 ms 104796 KB Output is correct
84 Correct 71 ms 116504 KB Output is correct
85 Correct 49 ms 96340 KB Output is correct
86 Correct 25 ms 108120 KB Output is correct
87 Correct 23 ms 107924 KB Output is correct
88 Correct 24 ms 107868 KB Output is correct
89 Correct 18 ms 107868 KB Output is correct
90 Correct 1 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 21 ms 53852 KB Output is correct
4 Runtime error 3 ms 856 KB Execution killed with signal 11
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 3 ms 18012 KB Output is correct
4 Correct 45 ms 100236 KB Output is correct
5 Correct 3 ms 30556 KB Output is correct
6 Correct 3 ms 35932 KB Output is correct
7 Correct 2 ms 18268 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 0 ms 2396 KB Output is correct
12 Correct 0 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 0 ms 2396 KB Output is correct
15 Correct 54 ms 110160 KB Output is correct
16 Correct 58 ms 94764 KB Output is correct
17 Correct 45 ms 95316 KB Output is correct
18 Correct 62 ms 117052 KB Output is correct
19 Correct 69 ms 121684 KB Output is correct
20 Correct 58 ms 112132 KB Output is correct
21 Correct 56 ms 110676 KB Output is correct
22 Correct 77 ms 116656 KB Output is correct
23 Correct 90 ms 112476 KB Output is correct
24 Correct 27 ms 76112 KB Output is correct
25 Correct 26 ms 76120 KB Output is correct
26 Correct 21 ms 67628 KB Output is correct
27 Correct 21 ms 68444 KB Output is correct
28 Correct 23 ms 67164 KB Output is correct
29 Correct 17 ms 62828 KB Output is correct
30 Correct 23 ms 66516 KB Output is correct
31 Correct 25 ms 69020 KB Output is correct
32 Correct 15 ms 59304 KB Output is correct
33 Correct 17 ms 63580 KB Output is correct
34 Correct 20 ms 69208 KB Output is correct
35 Correct 20 ms 65624 KB Output is correct
36 Correct 1 ms 5208 KB Output is correct
37 Correct 6 ms 32604 KB Output is correct
38 Correct 11 ms 35244 KB Output is correct
39 Correct 7 ms 33112 KB Output is correct
40 Correct 7 ms 34908 KB Output is correct
41 Correct 8 ms 35416 KB Output is correct
42 Correct 7 ms 52060 KB Output is correct
43 Correct 6 ms 51804 KB Output is correct
44 Correct 6 ms 51804 KB Output is correct
45 Correct 8 ms 51804 KB Output is correct
46 Correct 0 ms 2476 KB Output is correct
47 Correct 14 ms 38748 KB Output is correct
48 Correct 8 ms 14592 KB Output is correct
49 Correct 4 ms 26768 KB Output is correct
50 Correct 1 ms 4952 KB Output is correct
51 Correct 20 ms 36696 KB Output is correct
52 Correct 0 ms 2396 KB Output is correct
53 Correct 0 ms 4444 KB Output is correct
54 Correct 1 ms 2396 KB Output is correct
55 Correct 0 ms 2396 KB Output is correct
56 Correct 1 ms 2396 KB Output is correct
57 Correct 0 ms 2496 KB Output is correct
58 Correct 0 ms 2396 KB Output is correct
59 Correct 553 ms 627700 KB Output is correct
60 Correct 486 ms 621120 KB Output is correct
61 Correct 602 ms 597704 KB Output is correct
62 Correct 716 ms 765016 KB Output is correct
63 Correct 762 ms 701104 KB Output is correct
64 Correct 621 ms 603292 KB Output is correct
65 Correct 687 ms 738644 KB Output is correct
66 Correct 662 ms 674372 KB Output is correct
67 Correct 656 ms 605780 KB Output is correct
68 Correct 356 ms 407560 KB Output is correct
69 Correct 303 ms 355964 KB Output is correct
70 Correct 224 ms 289844 KB Output is correct
71 Correct 213 ms 271232 KB Output is correct
72 Correct 206 ms 247488 KB Output is correct
73 Correct 214 ms 230564 KB Output is correct
74 Correct 93 ms 174672 KB Output is correct
75 Correct 113 ms 169924 KB Output is correct
76 Correct 121 ms 186028 KB Output is correct
77 Correct 64 ms 145744 KB Output is correct
78 Correct 92 ms 179792 KB Output is correct
79 Correct 49 ms 141488 KB Output is correct
80 Correct 2 ms 5468 KB Output is correct
81 Correct 66 ms 101320 KB Output is correct
82 Correct 55 ms 104016 KB Output is correct
83 Correct 48 ms 104796 KB Output is correct
84 Correct 71 ms 116504 KB Output is correct
85 Correct 49 ms 96340 KB Output is correct
86 Correct 25 ms 108120 KB Output is correct
87 Correct 23 ms 107924 KB Output is correct
88 Correct 24 ms 107868 KB Output is correct
89 Correct 18 ms 107868 KB Output is correct
90 Correct 1 ms 2396 KB Output is correct
91 Correct 21 ms 53852 KB Output is correct
92 Runtime error 3 ms 856 KB Execution killed with signal 11
93 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 3 ms 18012 KB Output is correct
4 Correct 45 ms 100236 KB Output is correct
5 Correct 3 ms 30556 KB Output is correct
6 Correct 3 ms 35932 KB Output is correct
7 Correct 2 ms 18268 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 0 ms 2396 KB Output is correct
12 Correct 0 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 0 ms 2396 KB Output is correct
15 Correct 54 ms 110160 KB Output is correct
16 Correct 58 ms 94764 KB Output is correct
17 Correct 45 ms 95316 KB Output is correct
18 Correct 62 ms 117052 KB Output is correct
19 Correct 69 ms 121684 KB Output is correct
20 Correct 58 ms 112132 KB Output is correct
21 Correct 56 ms 110676 KB Output is correct
22 Correct 77 ms 116656 KB Output is correct
23 Correct 90 ms 112476 KB Output is correct
24 Correct 27 ms 76112 KB Output is correct
25 Correct 26 ms 76120 KB Output is correct
26 Correct 21 ms 67628 KB Output is correct
27 Correct 21 ms 68444 KB Output is correct
28 Correct 23 ms 67164 KB Output is correct
29 Correct 17 ms 62828 KB Output is correct
30 Correct 23 ms 66516 KB Output is correct
31 Correct 25 ms 69020 KB Output is correct
32 Correct 15 ms 59304 KB Output is correct
33 Correct 17 ms 63580 KB Output is correct
34 Correct 20 ms 69208 KB Output is correct
35 Correct 20 ms 65624 KB Output is correct
36 Correct 1 ms 5208 KB Output is correct
37 Correct 6 ms 32604 KB Output is correct
38 Correct 11 ms 35244 KB Output is correct
39 Correct 7 ms 33112 KB Output is correct
40 Correct 7 ms 34908 KB Output is correct
41 Correct 8 ms 35416 KB Output is correct
42 Correct 7 ms 52060 KB Output is correct
43 Correct 6 ms 51804 KB Output is correct
44 Correct 6 ms 51804 KB Output is correct
45 Correct 8 ms 51804 KB Output is correct
46 Correct 0 ms 2476 KB Output is correct
47 Correct 14 ms 38748 KB Output is correct
48 Correct 8 ms 14592 KB Output is correct
49 Correct 4 ms 26768 KB Output is correct
50 Correct 1 ms 4952 KB Output is correct
51 Correct 20 ms 36696 KB Output is correct
52 Correct 0 ms 2396 KB Output is correct
53 Correct 0 ms 4444 KB Output is correct
54 Correct 1 ms 2396 KB Output is correct
55 Correct 0 ms 2396 KB Output is correct
56 Correct 1 ms 2396 KB Output is correct
57 Correct 0 ms 2496 KB Output is correct
58 Correct 0 ms 2396 KB Output is correct
59 Correct 553 ms 627700 KB Output is correct
60 Correct 486 ms 621120 KB Output is correct
61 Correct 602 ms 597704 KB Output is correct
62 Correct 716 ms 765016 KB Output is correct
63 Correct 762 ms 701104 KB Output is correct
64 Correct 621 ms 603292 KB Output is correct
65 Correct 687 ms 738644 KB Output is correct
66 Correct 662 ms 674372 KB Output is correct
67 Correct 656 ms 605780 KB Output is correct
68 Correct 356 ms 407560 KB Output is correct
69 Correct 303 ms 355964 KB Output is correct
70 Correct 224 ms 289844 KB Output is correct
71 Correct 213 ms 271232 KB Output is correct
72 Correct 206 ms 247488 KB Output is correct
73 Correct 214 ms 230564 KB Output is correct
74 Correct 93 ms 174672 KB Output is correct
75 Correct 113 ms 169924 KB Output is correct
76 Correct 121 ms 186028 KB Output is correct
77 Correct 64 ms 145744 KB Output is correct
78 Correct 92 ms 179792 KB Output is correct
79 Correct 49 ms 141488 KB Output is correct
80 Correct 2 ms 5468 KB Output is correct
81 Correct 66 ms 101320 KB Output is correct
82 Correct 55 ms 104016 KB Output is correct
83 Correct 48 ms 104796 KB Output is correct
84 Correct 71 ms 116504 KB Output is correct
85 Correct 49 ms 96340 KB Output is correct
86 Correct 25 ms 108120 KB Output is correct
87 Correct 23 ms 107924 KB Output is correct
88 Correct 24 ms 107868 KB Output is correct
89 Correct 18 ms 107868 KB Output is correct
90 Correct 1 ms 2396 KB Output is correct
91 Correct 21 ms 53852 KB Output is correct
92 Runtime error 3 ms 856 KB Execution killed with signal 11
93 Halted 0 ms 0 KB -