답안 #1036515

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1036515 2024-07-27T13:28:08 Z model_code Toy (CEOI24_toy) C++17
35 / 100
1500 ms 776808 KB
// Author: Ondra Sladký
// State-based solution in O(w^2h^2).
// It should solve the first two subtasks.

#include <bits/stdc++.h>
using namespace std;
#define f(i, a, b) for (int i = (a); i < (b); i++)

#define v vector

int w, h, k, l;
int xhI, yhI, xvI, yvI;
int xt, yt;
v<v<bool>> grid;

v<v<bool>> validH;
v<v<bool>> validV;

v<v<v<v<bool>>>> states;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> w >> h >> k >> l;
    cin >> xhI >> yhI >> xvI >> yvI;
    grid = v<v<bool>>(w, v<bool>(h));
    f(i, 0, h) {
        string s;
        cin >> s;
        f(j, 0, w) {
            char x = s[j];
            grid[j][i] = x == 'X';
            if (x == '*') {
                xt = j;
                yt = i;
            }
        }
    }

    // Precompute valid positions for horizontal and vertical blocks.
    validH = v<v<bool>>(w, v<bool>(h, false));
    validV = v<v<bool>>(w, v<bool>(h, false));

    f(i,0,h) {
        int last = -1;
        f(j,0,w) {
            if (grid[j][i]) {
                last = j;
            }
            int start = j - k + 1;
            if (start > last) {
                validH[start][i] = true;
            }
        }
    }

    f(i,0,w) {
        int last = -1;
        f(j,0,h) {
            if (grid[i][j]) {
                last = j;
            }
            int start = j - l + 1;
            if (start > last) {
                validV[i][start] = true;
            }
        }
    }


    auto directions = v<tuple<int, int, int>> {
        {0, 1, 0},
        {0, -1, 0},
        {0, 0, 1},
        {0, 0, -1},
        {1, 1, 0},
        {1, -1, 0},
        {1, 0, 1},
        {1, 0, -1},
    };
    queue<tuple<int, int, int, int>> q;
    q.push({xhI, yhI, xvI, yvI});
    states = v<v<v<v<bool>>>>(w, v<v<v<bool>>>(h, v<v<bool>>(w, v<bool>(h, false))));
    states[xhI][yhI][xvI][yvI] = true;
    while (!q.empty()) {
        auto [xh, yh, xv, yv] = q.front();
        q.pop();
        for (auto [obj, dx, dy] : directions) {
            int nxh = xh + obj * dx;
            int nyh = yh + obj * dy;
            int nxv = xv + (!obj) * dx;
            int nyv = yv + (!obj) * dy;

            // Fast check for obstacles

            bool blocked = false;
            if (nxh < 0 || nxh >= w || nyh < 0 || nyh >= h) blocked = true;
            if (nxv < 0 || nxv >= w || nyv < 0 || nyv >= h) blocked = true;
            if (blocked) continue;
            if (!validH[nxh][nyh]) blocked = true;
            if (!validV[nxv][nyv]) blocked = true;

            // Check if the objects overlap.
            int nddx = nxv - nxh;
            int nddy = nyh - nyv;
            if (nddx < 0 || nddx >= k || nddy < 0 || nddy >= l) blocked = true;

            if (blocked) continue;

            if (states[nxh][nyh][nxv][nyv]) continue;
            states[nxh][nyh][nxv][nyv] = true;
            q.push({nxh, nyh, nxv, nyv});
        }
    }


    bool reached = false;
    f(i, 0, w) f(j, 0, h) {
        if (states[i][yt][xt][j]) {
            reached = true;
            break;
        }
    }

    cout << (reached ? "YES" : "NO") << endl;
}
# 결과 실행 시간 메모리 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 2 ms 1624 KB Output is correct
4 Correct 49 ms 9532 KB Output is correct
5 Correct 26 ms 9296 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 24 ms 9380 KB Output is correct
8 Correct 27 ms 9308 KB Output is correct
9 Correct 4 ms 2136 KB Output is correct
10 Correct 24 ms 9328 KB Output is correct
11 Correct 24 ms 9300 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 27 ms 9340 KB Output is correct
14 Correct 25 ms 9292 KB Output is correct
15 Correct 74 ms 8796 KB Output is correct
16 Correct 67 ms 8532 KB Output is correct
17 Correct 50 ms 8788 KB Output is correct
18 Correct 61 ms 9304 KB Output is correct
19 Correct 53 ms 9308 KB Output is correct
20 Correct 57 ms 9504 KB Output is correct
21 Correct 57 ms 9300 KB Output is correct
22 Correct 80 ms 9296 KB Output is correct
23 Correct 58 ms 9308 KB Output is correct
24 Correct 38 ms 9304 KB Output is correct
25 Correct 37 ms 9400 KB Output is correct
26 Correct 34 ms 9528 KB Output is correct
27 Correct 33 ms 9496 KB Output is correct
28 Correct 49 ms 9300 KB Output is correct
29 Correct 34 ms 9296 KB Output is correct
30 Correct 32 ms 8788 KB Output is correct
31 Correct 28 ms 7512 KB Output is correct
32 Correct 29 ms 8280 KB Output is correct
33 Correct 39 ms 9488 KB Output is correct
34 Correct 31 ms 7768 KB Output is correct
35 Correct 29 ms 8028 KB Output is correct
36 Correct 19 ms 7672 KB Output is correct
37 Correct 20 ms 7176 KB Output is correct
38 Correct 20 ms 7516 KB Output is correct
39 Correct 27 ms 7916 KB Output is correct
40 Correct 20 ms 7516 KB Output is correct
41 Correct 23 ms 8280 KB Output is correct
42 Correct 26 ms 9508 KB Output is correct
43 Correct 31 ms 9364 KB Output is correct
44 Correct 24 ms 9296 KB Output is correct
45 Correct 28 ms 9556 KB Output is correct
46 Correct 20 ms 7768 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 2 ms 1624 KB Output is correct
4 Correct 49 ms 9532 KB Output is correct
5 Correct 26 ms 9296 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 24 ms 9380 KB Output is correct
8 Correct 27 ms 9308 KB Output is correct
9 Correct 4 ms 2136 KB Output is correct
10 Correct 24 ms 9328 KB Output is correct
11 Correct 24 ms 9300 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 27 ms 9340 KB Output is correct
14 Correct 25 ms 9292 KB Output is correct
15 Correct 74 ms 8796 KB Output is correct
16 Correct 67 ms 8532 KB Output is correct
17 Correct 50 ms 8788 KB Output is correct
18 Correct 61 ms 9304 KB Output is correct
19 Correct 53 ms 9308 KB Output is correct
20 Correct 57 ms 9504 KB Output is correct
21 Correct 57 ms 9300 KB Output is correct
22 Correct 80 ms 9296 KB Output is correct
23 Correct 58 ms 9308 KB Output is correct
24 Correct 38 ms 9304 KB Output is correct
25 Correct 37 ms 9400 KB Output is correct
26 Correct 34 ms 9528 KB Output is correct
27 Correct 33 ms 9496 KB Output is correct
28 Correct 49 ms 9300 KB Output is correct
29 Correct 34 ms 9296 KB Output is correct
30 Correct 32 ms 8788 KB Output is correct
31 Correct 28 ms 7512 KB Output is correct
32 Correct 29 ms 8280 KB Output is correct
33 Correct 39 ms 9488 KB Output is correct
34 Correct 31 ms 7768 KB Output is correct
35 Correct 29 ms 8028 KB Output is correct
36 Correct 19 ms 7672 KB Output is correct
37 Correct 20 ms 7176 KB Output is correct
38 Correct 20 ms 7516 KB Output is correct
39 Correct 27 ms 7916 KB Output is correct
40 Correct 20 ms 7516 KB Output is correct
41 Correct 23 ms 8280 KB Output is correct
42 Correct 26 ms 9508 KB Output is correct
43 Correct 31 ms 9364 KB Output is correct
44 Correct 24 ms 9296 KB Output is correct
45 Correct 28 ms 9556 KB Output is correct
46 Correct 20 ms 7768 KB Output is correct
47 Correct 21 ms 8796 KB Output is correct
48 Correct 106 ms 52564 KB Output is correct
49 Correct 108 ms 52576 KB Output is correct
50 Correct 58 ms 33416 KB Output is correct
51 Correct 119 ms 52564 KB Output is correct
52 Correct 88 ms 52568 KB Output is correct
53 Correct 85 ms 28756 KB Output is correct
54 Correct 91 ms 52512 KB Output is correct
55 Correct 91 ms 52568 KB Output is correct
56 Correct 11 ms 6412 KB Output is correct
57 Correct 91 ms 52520 KB Output is correct
58 Correct 89 ms 52564 KB Output is correct
59 Correct 391 ms 44528 KB Output is correct
60 Correct 334 ms 41472 KB Output is correct
61 Correct 405 ms 46596 KB Output is correct
62 Correct 456 ms 52608 KB Output is correct
63 Correct 440 ms 52564 KB Output is correct
64 Correct 477 ms 52768 KB Output is correct
65 Correct 457 ms 52792 KB Output is correct
66 Correct 432 ms 52684 KB Output is correct
67 Correct 461 ms 52564 KB Output is correct
68 Correct 228 ms 52548 KB Output is correct
69 Correct 246 ms 52664 KB Output is correct
70 Correct 194 ms 52712 KB Output is correct
71 Correct 204 ms 52676 KB Output is correct
72 Correct 192 ms 52560 KB Output is correct
73 Correct 185 ms 52564 KB Output is correct
74 Correct 123 ms 44372 KB Output is correct
75 Correct 103 ms 46796 KB Output is correct
76 Correct 135 ms 52608 KB Output is correct
77 Correct 99 ms 47444 KB Output is correct
78 Correct 121 ms 51284 KB Output is correct
79 Correct 92 ms 43820 KB Output is correct
80 Correct 76 ms 46928 KB Output is correct
81 Correct 97 ms 41812 KB Output is correct
82 Correct 99 ms 45904 KB Output is correct
83 Correct 81 ms 40364 KB Output is correct
84 Correct 100 ms 49024 KB Output is correct
85 Correct 100 ms 42324 KB Output is correct
86 Correct 88 ms 52560 KB Output is correct
87 Correct 90 ms 52564 KB Output is correct
88 Correct 86 ms 52560 KB Output is correct
89 Correct 90 ms 52560 KB Output is correct
90 Correct 85 ms 52052 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 54 ms 24660 KB Output is correct
4 Execution timed out 1612 ms 776808 KB Time limit exceeded
5 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 2 ms 1624 KB Output is correct
4 Correct 49 ms 9532 KB Output is correct
5 Correct 26 ms 9296 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 24 ms 9380 KB Output is correct
8 Correct 27 ms 9308 KB Output is correct
9 Correct 4 ms 2136 KB Output is correct
10 Correct 24 ms 9328 KB Output is correct
11 Correct 24 ms 9300 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 27 ms 9340 KB Output is correct
14 Correct 25 ms 9292 KB Output is correct
15 Correct 74 ms 8796 KB Output is correct
16 Correct 67 ms 8532 KB Output is correct
17 Correct 50 ms 8788 KB Output is correct
18 Correct 61 ms 9304 KB Output is correct
19 Correct 53 ms 9308 KB Output is correct
20 Correct 57 ms 9504 KB Output is correct
21 Correct 57 ms 9300 KB Output is correct
22 Correct 80 ms 9296 KB Output is correct
23 Correct 58 ms 9308 KB Output is correct
24 Correct 38 ms 9304 KB Output is correct
25 Correct 37 ms 9400 KB Output is correct
26 Correct 34 ms 9528 KB Output is correct
27 Correct 33 ms 9496 KB Output is correct
28 Correct 49 ms 9300 KB Output is correct
29 Correct 34 ms 9296 KB Output is correct
30 Correct 32 ms 8788 KB Output is correct
31 Correct 28 ms 7512 KB Output is correct
32 Correct 29 ms 8280 KB Output is correct
33 Correct 39 ms 9488 KB Output is correct
34 Correct 31 ms 7768 KB Output is correct
35 Correct 29 ms 8028 KB Output is correct
36 Correct 19 ms 7672 KB Output is correct
37 Correct 20 ms 7176 KB Output is correct
38 Correct 20 ms 7516 KB Output is correct
39 Correct 27 ms 7916 KB Output is correct
40 Correct 20 ms 7516 KB Output is correct
41 Correct 23 ms 8280 KB Output is correct
42 Correct 26 ms 9508 KB Output is correct
43 Correct 31 ms 9364 KB Output is correct
44 Correct 24 ms 9296 KB Output is correct
45 Correct 28 ms 9556 KB Output is correct
46 Correct 20 ms 7768 KB Output is correct
47 Correct 21 ms 8796 KB Output is correct
48 Correct 106 ms 52564 KB Output is correct
49 Correct 108 ms 52576 KB Output is correct
50 Correct 58 ms 33416 KB Output is correct
51 Correct 119 ms 52564 KB Output is correct
52 Correct 88 ms 52568 KB Output is correct
53 Correct 85 ms 28756 KB Output is correct
54 Correct 91 ms 52512 KB Output is correct
55 Correct 91 ms 52568 KB Output is correct
56 Correct 11 ms 6412 KB Output is correct
57 Correct 91 ms 52520 KB Output is correct
58 Correct 89 ms 52564 KB Output is correct
59 Correct 391 ms 44528 KB Output is correct
60 Correct 334 ms 41472 KB Output is correct
61 Correct 405 ms 46596 KB Output is correct
62 Correct 456 ms 52608 KB Output is correct
63 Correct 440 ms 52564 KB Output is correct
64 Correct 477 ms 52768 KB Output is correct
65 Correct 457 ms 52792 KB Output is correct
66 Correct 432 ms 52684 KB Output is correct
67 Correct 461 ms 52564 KB Output is correct
68 Correct 228 ms 52548 KB Output is correct
69 Correct 246 ms 52664 KB Output is correct
70 Correct 194 ms 52712 KB Output is correct
71 Correct 204 ms 52676 KB Output is correct
72 Correct 192 ms 52560 KB Output is correct
73 Correct 185 ms 52564 KB Output is correct
74 Correct 123 ms 44372 KB Output is correct
75 Correct 103 ms 46796 KB Output is correct
76 Correct 135 ms 52608 KB Output is correct
77 Correct 99 ms 47444 KB Output is correct
78 Correct 121 ms 51284 KB Output is correct
79 Correct 92 ms 43820 KB Output is correct
80 Correct 76 ms 46928 KB Output is correct
81 Correct 97 ms 41812 KB Output is correct
82 Correct 99 ms 45904 KB Output is correct
83 Correct 81 ms 40364 KB Output is correct
84 Correct 100 ms 49024 KB Output is correct
85 Correct 100 ms 42324 KB Output is correct
86 Correct 88 ms 52560 KB Output is correct
87 Correct 90 ms 52564 KB Output is correct
88 Correct 86 ms 52560 KB Output is correct
89 Correct 90 ms 52560 KB Output is correct
90 Correct 85 ms 52052 KB Output is correct
91 Correct 54 ms 24660 KB Output is correct
92 Execution timed out 1612 ms 776808 KB Time limit exceeded
93 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 2 ms 1624 KB Output is correct
4 Correct 49 ms 9532 KB Output is correct
5 Correct 26 ms 9296 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 24 ms 9380 KB Output is correct
8 Correct 27 ms 9308 KB Output is correct
9 Correct 4 ms 2136 KB Output is correct
10 Correct 24 ms 9328 KB Output is correct
11 Correct 24 ms 9300 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 27 ms 9340 KB Output is correct
14 Correct 25 ms 9292 KB Output is correct
15 Correct 74 ms 8796 KB Output is correct
16 Correct 67 ms 8532 KB Output is correct
17 Correct 50 ms 8788 KB Output is correct
18 Correct 61 ms 9304 KB Output is correct
19 Correct 53 ms 9308 KB Output is correct
20 Correct 57 ms 9504 KB Output is correct
21 Correct 57 ms 9300 KB Output is correct
22 Correct 80 ms 9296 KB Output is correct
23 Correct 58 ms 9308 KB Output is correct
24 Correct 38 ms 9304 KB Output is correct
25 Correct 37 ms 9400 KB Output is correct
26 Correct 34 ms 9528 KB Output is correct
27 Correct 33 ms 9496 KB Output is correct
28 Correct 49 ms 9300 KB Output is correct
29 Correct 34 ms 9296 KB Output is correct
30 Correct 32 ms 8788 KB Output is correct
31 Correct 28 ms 7512 KB Output is correct
32 Correct 29 ms 8280 KB Output is correct
33 Correct 39 ms 9488 KB Output is correct
34 Correct 31 ms 7768 KB Output is correct
35 Correct 29 ms 8028 KB Output is correct
36 Correct 19 ms 7672 KB Output is correct
37 Correct 20 ms 7176 KB Output is correct
38 Correct 20 ms 7516 KB Output is correct
39 Correct 27 ms 7916 KB Output is correct
40 Correct 20 ms 7516 KB Output is correct
41 Correct 23 ms 8280 KB Output is correct
42 Correct 26 ms 9508 KB Output is correct
43 Correct 31 ms 9364 KB Output is correct
44 Correct 24 ms 9296 KB Output is correct
45 Correct 28 ms 9556 KB Output is correct
46 Correct 20 ms 7768 KB Output is correct
47 Correct 21 ms 8796 KB Output is correct
48 Correct 106 ms 52564 KB Output is correct
49 Correct 108 ms 52576 KB Output is correct
50 Correct 58 ms 33416 KB Output is correct
51 Correct 119 ms 52564 KB Output is correct
52 Correct 88 ms 52568 KB Output is correct
53 Correct 85 ms 28756 KB Output is correct
54 Correct 91 ms 52512 KB Output is correct
55 Correct 91 ms 52568 KB Output is correct
56 Correct 11 ms 6412 KB Output is correct
57 Correct 91 ms 52520 KB Output is correct
58 Correct 89 ms 52564 KB Output is correct
59 Correct 391 ms 44528 KB Output is correct
60 Correct 334 ms 41472 KB Output is correct
61 Correct 405 ms 46596 KB Output is correct
62 Correct 456 ms 52608 KB Output is correct
63 Correct 440 ms 52564 KB Output is correct
64 Correct 477 ms 52768 KB Output is correct
65 Correct 457 ms 52792 KB Output is correct
66 Correct 432 ms 52684 KB Output is correct
67 Correct 461 ms 52564 KB Output is correct
68 Correct 228 ms 52548 KB Output is correct
69 Correct 246 ms 52664 KB Output is correct
70 Correct 194 ms 52712 KB Output is correct
71 Correct 204 ms 52676 KB Output is correct
72 Correct 192 ms 52560 KB Output is correct
73 Correct 185 ms 52564 KB Output is correct
74 Correct 123 ms 44372 KB Output is correct
75 Correct 103 ms 46796 KB Output is correct
76 Correct 135 ms 52608 KB Output is correct
77 Correct 99 ms 47444 KB Output is correct
78 Correct 121 ms 51284 KB Output is correct
79 Correct 92 ms 43820 KB Output is correct
80 Correct 76 ms 46928 KB Output is correct
81 Correct 97 ms 41812 KB Output is correct
82 Correct 99 ms 45904 KB Output is correct
83 Correct 81 ms 40364 KB Output is correct
84 Correct 100 ms 49024 KB Output is correct
85 Correct 100 ms 42324 KB Output is correct
86 Correct 88 ms 52560 KB Output is correct
87 Correct 90 ms 52564 KB Output is correct
88 Correct 86 ms 52560 KB Output is correct
89 Correct 90 ms 52560 KB Output is correct
90 Correct 85 ms 52052 KB Output is correct
91 Correct 54 ms 24660 KB Output is correct
92 Execution timed out 1612 ms 776808 KB Time limit exceeded
93 Halted 0 ms 0 KB -