답안 #1045747

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1045747 2024-08-06T07:22:35 Z VahanAbraham Toy (CEOI24_toy) C++17
35 / 100
1203 ms 35412 KB
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <sstream>
#include <map>
#include <stack>
#include <set>
#include <queue>
#include <list>
#include <unordered_set>
#include <unordered_map>
#include <math.h>
#include <bitset>
#include <cmath>
#include <vector>
#include <iomanip>
#include <random>
#include <chrono>
#include <cassert>

using namespace std;

#define ll long long
#define fr first
#define sc second
#define pb push_back
#define US freopen(".in", "r", stdin); freopen("j.out", "w", stdout);

ll gcd(ll a, ll b)
{
    if (a == 0 || b == 0) {
        return  max(a, b);
    }
    if (a <= b) {
        return gcd(a, b % a);
    }
    else {
        return gcd(a % b, b);
    }
}
ll lcm(ll a, ll b) {
    return (a / gcd(a, b)) * b;
}

const int N = 93;
const ll oo = 100000000000000000, MOD = 1000000007;

struct cord {
    int x, y;
};

char grid[N][N];
bool ok[N][N][N][N], normalahor[N][N], normalaver[N][N];
int w, h, k, l, xend, yend;

int dxhor[3] = { 1,-1,0 };
int dxver[3] = { 1,-1,0 };
int dyhor[3] = { 1,-1,0 };
int dyver[3] = { 1,-1,0 };

queue<pair<cord, cord>> q;

pair<int, int> hatvumen(cord hor, cord ver) {
    for (int i = ver.x; i <= ver.x; ++i) {
        if (hor.y >= ver.y && hor.y <= ver.y + l - 1 && i >=hor.x && i<=hor.x+k-1) {
            return { i,hor.y };
        }
    }
    return{ -1,-1 };
}

bool mejnahor(cord hor) {
    if (hor.x >= 0 && hor.x + k - 1 <= w - 1 && hor.y >= 0 && hor.y <= h - 1) {
        return true;
    }
    return false;
}

bool mejnaver(cord ver) {
    if (ver.x >= 0 && ver.x <= w - 1 && ver.y >= 0 && ver.y+l-1 <= h - 1) {
        return true;
    }
    return false;
}

bool normalhor(cord hor) {
    for (int i = hor.x; i <= hor.x + k - 1; ++i) {
        if (grid[hor.y][i] == 'X') {
            return false;
        }
    }
    return true;
}

bool normalver(cord ver) {
    for (int i = ver.y; i <= ver.y + l - 1; ++i) {
        if (grid[i][ver.x] == 'X') {
            return false;
        }
    }
    return true;
}

bool stug(cord hor1, cord ver1) {
    if (mejnahor(hor1) == 1 && mejnaver(ver1) == 1 && normalahor[hor1.x][hor1.y] == 1 && normalaver[ver1.x][ver1.y] == 1) {
        pair<int, int> p = hatvumen(hor1, ver1);
        if (p.fr == xend && p.sc == yend){
            return true;
        }
        else {
            if (p.fr != -1) {
                if (ok[hor1.x][hor1.y][ver1.x][ver1.y] != 1) {
                    ok[hor1.x][hor1.y][ver1.x][ver1.y] = 1;
                    q.push({ hor1,ver1 });
                    return false;
                }
                return false;
            }
            return false;
        }
        return false;
    }
    return false;
}


void solve() {
    cin >> w >> h >> k >> l;
    int xh, yh, xv, yv;
    cin >> xh >> yh >> xv >> yv;
    cord hor, ver;
    hor.x = xh;
    hor.y = yh;
    ver.x = xv;
    ver.y = yv;
    ok[hor.x][hor.y][ver.x][ver.y] = 1;
    q.push({ hor,ver });
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            cin >> grid[i][j];
            if (grid[i][j] == '*') {
                xend = j, yend = i;
            }
        }
    }
    /*cout << xend << " " << yend << endl;
    cord vv;
    vv.x = 1, vv.y = 0;
    cout << normalver(vv) << endl;*/
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            cord yy;
            yy.x = j, yy.y = i;
            if (mejnaver(yy)) {
                normalaver[j][i] = normalver(yy);
            }
            if (mejnahor(yy)) {
                normalahor[j][i] = normalhor(yy);
            }
        }
    }
    while (q.empty() != 1) {
        hor = q.front().fr;
        ver = q.front().sc;
        //cout << hor.x << " " << hor.y << " " << ver.x << " " << ver.y << endl;
        q.pop();
        for (int i = 0; i < 3; ++i) {
            for (int j = 0; j < 3; ++j) {
                cord hor1 = hor, ver1 = ver;
                hor1.x += dxhor[i];
                ver1.x += dxver[j];
                if (stug(hor1, ver1)) {
                    //cout << hor1.x << " " << hor1.y << " " << ver1.x << " " << ver1.y << endl;
                    cout << "YES" << endl;
                    return;
                }
            }
            for (int j = 0; j < 3; ++j) {
                cord hor1 = hor, ver1 = ver;
                hor1.x += dxhor[i];
                ver1.y += dyver[j];
                if (stug(hor1, ver1)) {
                    //cout << hor1.x << " " << hor1.y << " " << ver1.x << " " << ver1.y << endl;
                    cout << "YES" << endl;
                    return;
                }
            }
        }
        for (int i = 0; i < 3; ++i) {
            for (int j = 0; j < 3; ++j) {
                cord hor1 = hor, ver1 = ver;
                hor1.y += dyhor[i];
                ver1.x += dxver[j];
                if (stug(hor1, ver1)) {
                    //cout << hor1.x << " " << hor1.y << " " << ver1.x << " " << ver1.y << endl;
                    cout << "YES" << endl;
                    return;
                }
            }
            for (int j = 0; j < 3; ++j) {
                cord hor1 = hor, ver1 = ver;
                hor1.y += dyhor[i];
                ver1.y += dyver[j];
                if (stug(hor1, ver1)) {
                    //cout << hor1.x << " " << hor1.y << " " << ver1.x << " " << ver1.y << endl;
                    cout << "YES" << endl;
                    return;
                }
            }
        }
    }
    cout << "NO" << endl;
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    //US
    int tt = 1;
    //cin >> tt;
    while (tt--) {
        solve();
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 2652 KB Output is correct
4 Correct 1 ms 2652 KB Output is correct
5 Correct 0 ms 604 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 3 ms 3676 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 348 KB Output is correct
13 Correct 0 ms 2396 KB Output is correct
14 Correct 0 ms 2396 KB Output is correct
15 Correct 104 ms 9376 KB Output is correct
16 Correct 87 ms 9300 KB Output is correct
17 Correct 98 ms 9552 KB Output is correct
18 Correct 130 ms 8764 KB Output is correct
19 Correct 113 ms 8788 KB Output is correct
20 Correct 115 ms 8900 KB Output is correct
21 Correct 118 ms 8528 KB Output is correct
22 Correct 117 ms 8764 KB Output is correct
23 Correct 121 ms 9076 KB Output is correct
24 Correct 56 ms 8788 KB Output is correct
25 Correct 47 ms 8956 KB Output is correct
26 Correct 40 ms 8016 KB Output is correct
27 Correct 39 ms 8272 KB Output is correct
28 Correct 33 ms 8532 KB Output is correct
29 Correct 30 ms 8784 KB Output is correct
30 Correct 12 ms 4184 KB Output is correct
31 Correct 39 ms 8672 KB Output is correct
32 Correct 8 ms 4444 KB Output is correct
33 Correct 24 ms 10336 KB Output is correct
34 Correct 19 ms 4956 KB Output is correct
35 Correct 24 ms 5964 KB Output is correct
36 Correct 1 ms 2652 KB Output is correct
37 Correct 9 ms 2392 KB Output is correct
38 Correct 10 ms 2500 KB Output is correct
39 Correct 9 ms 2648 KB Output is correct
40 Correct 10 ms 2652 KB Output is correct
41 Correct 10 ms 2644 KB Output is correct
42 Correct 1 ms 2480 KB Output is correct
43 Correct 1 ms 2652 KB Output is correct
44 Correct 0 ms 2396 KB Output is correct
45 Correct 0 ms 348 KB Output is correct
46 Correct 0 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 2652 KB Output is correct
4 Correct 1 ms 2652 KB Output is correct
5 Correct 0 ms 604 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 3 ms 3676 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 348 KB Output is correct
13 Correct 0 ms 2396 KB Output is correct
14 Correct 0 ms 2396 KB Output is correct
15 Correct 104 ms 9376 KB Output is correct
16 Correct 87 ms 9300 KB Output is correct
17 Correct 98 ms 9552 KB Output is correct
18 Correct 130 ms 8764 KB Output is correct
19 Correct 113 ms 8788 KB Output is correct
20 Correct 115 ms 8900 KB Output is correct
21 Correct 118 ms 8528 KB Output is correct
22 Correct 117 ms 8764 KB Output is correct
23 Correct 121 ms 9076 KB Output is correct
24 Correct 56 ms 8788 KB Output is correct
25 Correct 47 ms 8956 KB Output is correct
26 Correct 40 ms 8016 KB Output is correct
27 Correct 39 ms 8272 KB Output is correct
28 Correct 33 ms 8532 KB Output is correct
29 Correct 30 ms 8784 KB Output is correct
30 Correct 12 ms 4184 KB Output is correct
31 Correct 39 ms 8672 KB Output is correct
32 Correct 8 ms 4444 KB Output is correct
33 Correct 24 ms 10336 KB Output is correct
34 Correct 19 ms 4956 KB Output is correct
35 Correct 24 ms 5964 KB Output is correct
36 Correct 1 ms 2652 KB Output is correct
37 Correct 9 ms 2392 KB Output is correct
38 Correct 10 ms 2500 KB Output is correct
39 Correct 9 ms 2648 KB Output is correct
40 Correct 10 ms 2652 KB Output is correct
41 Correct 10 ms 2644 KB Output is correct
42 Correct 1 ms 2480 KB Output is correct
43 Correct 1 ms 2652 KB Output is correct
44 Correct 0 ms 2396 KB Output is correct
45 Correct 0 ms 348 KB Output is correct
46 Correct 0 ms 344 KB Output is correct
47 Correct 18 ms 6232 KB Output is correct
48 Correct 19 ms 3164 KB Output is correct
49 Correct 1 ms 2396 KB Output is correct
50 Correct 1 ms 2396 KB Output is correct
51 Correct 41 ms 4600 KB Output is correct
52 Correct 1 ms 2392 KB Output is correct
53 Correct 1 ms 2392 KB Output is correct
54 Correct 0 ms 2396 KB Output is correct
55 Correct 1 ms 2396 KB Output is correct
56 Correct 0 ms 2396 KB Output is correct
57 Correct 0 ms 2396 KB Output is correct
58 Correct 0 ms 348 KB Output is correct
59 Correct 938 ms 32220 KB Output is correct
60 Correct 853 ms 30412 KB Output is correct
61 Correct 893 ms 32436 KB Output is correct
62 Correct 1203 ms 34900 KB Output is correct
63 Correct 1139 ms 35264 KB Output is correct
64 Correct 1123 ms 35412 KB Output is correct
65 Correct 1175 ms 34984 KB Output is correct
66 Correct 1144 ms 35156 KB Output is correct
67 Correct 1118 ms 35412 KB Output is correct
68 Correct 518 ms 31824 KB Output is correct
69 Correct 499 ms 32084 KB Output is correct
70 Correct 376 ms 28836 KB Output is correct
71 Correct 368 ms 29268 KB Output is correct
72 Correct 352 ms 29520 KB Output is correct
73 Correct 333 ms 30024 KB Output is correct
74 Correct 118 ms 22252 KB Output is correct
75 Correct 140 ms 31828 KB Output is correct
76 Correct 83 ms 20308 KB Output is correct
77 Correct 77 ms 32592 KB Output is correct
78 Correct 51 ms 12368 KB Output is correct
79 Correct 61 ms 26708 KB Output is correct
80 Correct 4 ms 2908 KB Output is correct
81 Correct 109 ms 7884 KB Output is correct
82 Correct 96 ms 8788 KB Output is correct
83 Correct 80 ms 7504 KB Output is correct
84 Correct 109 ms 9320 KB Output is correct
85 Correct 90 ms 8300 KB Output is correct
86 Correct 1 ms 2392 KB Output is correct
87 Correct 2 ms 2392 KB Output is correct
88 Correct 1 ms 2652 KB Output is correct
89 Correct 1 ms 2396 KB Output is correct
90 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Runtime error 11 ms 10332 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 2652 KB Output is correct
4 Correct 1 ms 2652 KB Output is correct
5 Correct 0 ms 604 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 3 ms 3676 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 348 KB Output is correct
13 Correct 0 ms 2396 KB Output is correct
14 Correct 0 ms 2396 KB Output is correct
15 Correct 104 ms 9376 KB Output is correct
16 Correct 87 ms 9300 KB Output is correct
17 Correct 98 ms 9552 KB Output is correct
18 Correct 130 ms 8764 KB Output is correct
19 Correct 113 ms 8788 KB Output is correct
20 Correct 115 ms 8900 KB Output is correct
21 Correct 118 ms 8528 KB Output is correct
22 Correct 117 ms 8764 KB Output is correct
23 Correct 121 ms 9076 KB Output is correct
24 Correct 56 ms 8788 KB Output is correct
25 Correct 47 ms 8956 KB Output is correct
26 Correct 40 ms 8016 KB Output is correct
27 Correct 39 ms 8272 KB Output is correct
28 Correct 33 ms 8532 KB Output is correct
29 Correct 30 ms 8784 KB Output is correct
30 Correct 12 ms 4184 KB Output is correct
31 Correct 39 ms 8672 KB Output is correct
32 Correct 8 ms 4444 KB Output is correct
33 Correct 24 ms 10336 KB Output is correct
34 Correct 19 ms 4956 KB Output is correct
35 Correct 24 ms 5964 KB Output is correct
36 Correct 1 ms 2652 KB Output is correct
37 Correct 9 ms 2392 KB Output is correct
38 Correct 10 ms 2500 KB Output is correct
39 Correct 9 ms 2648 KB Output is correct
40 Correct 10 ms 2652 KB Output is correct
41 Correct 10 ms 2644 KB Output is correct
42 Correct 1 ms 2480 KB Output is correct
43 Correct 1 ms 2652 KB Output is correct
44 Correct 0 ms 2396 KB Output is correct
45 Correct 0 ms 348 KB Output is correct
46 Correct 0 ms 344 KB Output is correct
47 Correct 18 ms 6232 KB Output is correct
48 Correct 19 ms 3164 KB Output is correct
49 Correct 1 ms 2396 KB Output is correct
50 Correct 1 ms 2396 KB Output is correct
51 Correct 41 ms 4600 KB Output is correct
52 Correct 1 ms 2392 KB Output is correct
53 Correct 1 ms 2392 KB Output is correct
54 Correct 0 ms 2396 KB Output is correct
55 Correct 1 ms 2396 KB Output is correct
56 Correct 0 ms 2396 KB Output is correct
57 Correct 0 ms 2396 KB Output is correct
58 Correct 0 ms 348 KB Output is correct
59 Correct 938 ms 32220 KB Output is correct
60 Correct 853 ms 30412 KB Output is correct
61 Correct 893 ms 32436 KB Output is correct
62 Correct 1203 ms 34900 KB Output is correct
63 Correct 1139 ms 35264 KB Output is correct
64 Correct 1123 ms 35412 KB Output is correct
65 Correct 1175 ms 34984 KB Output is correct
66 Correct 1144 ms 35156 KB Output is correct
67 Correct 1118 ms 35412 KB Output is correct
68 Correct 518 ms 31824 KB Output is correct
69 Correct 499 ms 32084 KB Output is correct
70 Correct 376 ms 28836 KB Output is correct
71 Correct 368 ms 29268 KB Output is correct
72 Correct 352 ms 29520 KB Output is correct
73 Correct 333 ms 30024 KB Output is correct
74 Correct 118 ms 22252 KB Output is correct
75 Correct 140 ms 31828 KB Output is correct
76 Correct 83 ms 20308 KB Output is correct
77 Correct 77 ms 32592 KB Output is correct
78 Correct 51 ms 12368 KB Output is correct
79 Correct 61 ms 26708 KB Output is correct
80 Correct 4 ms 2908 KB Output is correct
81 Correct 109 ms 7884 KB Output is correct
82 Correct 96 ms 8788 KB Output is correct
83 Correct 80 ms 7504 KB Output is correct
84 Correct 109 ms 9320 KB Output is correct
85 Correct 90 ms 8300 KB Output is correct
86 Correct 1 ms 2392 KB Output is correct
87 Correct 2 ms 2392 KB Output is correct
88 Correct 1 ms 2652 KB Output is correct
89 Correct 1 ms 2396 KB Output is correct
90 Correct 0 ms 348 KB Output is correct
91 Runtime error 11 ms 10332 KB Execution killed with signal 11
92 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 2652 KB Output is correct
4 Correct 1 ms 2652 KB Output is correct
5 Correct 0 ms 604 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 3 ms 3676 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 348 KB Output is correct
13 Correct 0 ms 2396 KB Output is correct
14 Correct 0 ms 2396 KB Output is correct
15 Correct 104 ms 9376 KB Output is correct
16 Correct 87 ms 9300 KB Output is correct
17 Correct 98 ms 9552 KB Output is correct
18 Correct 130 ms 8764 KB Output is correct
19 Correct 113 ms 8788 KB Output is correct
20 Correct 115 ms 8900 KB Output is correct
21 Correct 118 ms 8528 KB Output is correct
22 Correct 117 ms 8764 KB Output is correct
23 Correct 121 ms 9076 KB Output is correct
24 Correct 56 ms 8788 KB Output is correct
25 Correct 47 ms 8956 KB Output is correct
26 Correct 40 ms 8016 KB Output is correct
27 Correct 39 ms 8272 KB Output is correct
28 Correct 33 ms 8532 KB Output is correct
29 Correct 30 ms 8784 KB Output is correct
30 Correct 12 ms 4184 KB Output is correct
31 Correct 39 ms 8672 KB Output is correct
32 Correct 8 ms 4444 KB Output is correct
33 Correct 24 ms 10336 KB Output is correct
34 Correct 19 ms 4956 KB Output is correct
35 Correct 24 ms 5964 KB Output is correct
36 Correct 1 ms 2652 KB Output is correct
37 Correct 9 ms 2392 KB Output is correct
38 Correct 10 ms 2500 KB Output is correct
39 Correct 9 ms 2648 KB Output is correct
40 Correct 10 ms 2652 KB Output is correct
41 Correct 10 ms 2644 KB Output is correct
42 Correct 1 ms 2480 KB Output is correct
43 Correct 1 ms 2652 KB Output is correct
44 Correct 0 ms 2396 KB Output is correct
45 Correct 0 ms 348 KB Output is correct
46 Correct 0 ms 344 KB Output is correct
47 Correct 18 ms 6232 KB Output is correct
48 Correct 19 ms 3164 KB Output is correct
49 Correct 1 ms 2396 KB Output is correct
50 Correct 1 ms 2396 KB Output is correct
51 Correct 41 ms 4600 KB Output is correct
52 Correct 1 ms 2392 KB Output is correct
53 Correct 1 ms 2392 KB Output is correct
54 Correct 0 ms 2396 KB Output is correct
55 Correct 1 ms 2396 KB Output is correct
56 Correct 0 ms 2396 KB Output is correct
57 Correct 0 ms 2396 KB Output is correct
58 Correct 0 ms 348 KB Output is correct
59 Correct 938 ms 32220 KB Output is correct
60 Correct 853 ms 30412 KB Output is correct
61 Correct 893 ms 32436 KB Output is correct
62 Correct 1203 ms 34900 KB Output is correct
63 Correct 1139 ms 35264 KB Output is correct
64 Correct 1123 ms 35412 KB Output is correct
65 Correct 1175 ms 34984 KB Output is correct
66 Correct 1144 ms 35156 KB Output is correct
67 Correct 1118 ms 35412 KB Output is correct
68 Correct 518 ms 31824 KB Output is correct
69 Correct 499 ms 32084 KB Output is correct
70 Correct 376 ms 28836 KB Output is correct
71 Correct 368 ms 29268 KB Output is correct
72 Correct 352 ms 29520 KB Output is correct
73 Correct 333 ms 30024 KB Output is correct
74 Correct 118 ms 22252 KB Output is correct
75 Correct 140 ms 31828 KB Output is correct
76 Correct 83 ms 20308 KB Output is correct
77 Correct 77 ms 32592 KB Output is correct
78 Correct 51 ms 12368 KB Output is correct
79 Correct 61 ms 26708 KB Output is correct
80 Correct 4 ms 2908 KB Output is correct
81 Correct 109 ms 7884 KB Output is correct
82 Correct 96 ms 8788 KB Output is correct
83 Correct 80 ms 7504 KB Output is correct
84 Correct 109 ms 9320 KB Output is correct
85 Correct 90 ms 8300 KB Output is correct
86 Correct 1 ms 2392 KB Output is correct
87 Correct 2 ms 2392 KB Output is correct
88 Correct 1 ms 2652 KB Output is correct
89 Correct 1 ms 2396 KB Output is correct
90 Correct 0 ms 348 KB Output is correct
91 Runtime error 11 ms 10332 KB Execution killed with signal 11
92 Halted 0 ms 0 KB -