Submission #1365478

#TimeUsernameProblemLanguageResultExecution timeMemory
1365478kahoulToy (CEOI24_toy)C++20
Compilation error
0 ms0 KiB
#include <bits/stdc++.h>
using namespace std;

int main () {
    int w, h, k, l;
    cin >> w >> h >> k >> l;

    int xh, yh, xv, yv;
    cin >> xh >> yh >> xv >> yv;

    int destx = -1, desty = -1;

    char placed[h][w];

    for (int y = 0; y < h; y++) {
        for (int x = 0; x < w; x++) {
            cin >> placed[y][x];
            if (placed[y][x] == '*') {
                desty = y;
                destx = x;
            }
        }
    }

    vector<vector<bool>> visited(h, vector<bool>(w, 0));
    vector<vector<int>> left (h, vector<int>(w, 0));
    vector<vector<int>> right(h, vector<int>(h, 0));
    vector<vector<int>> up   (h, vector<int>(w, 0));
    vector<vector<int>> down (h, vector<int>(h, 0));

    for (int y = 0; y < h; y++) {
        int leftmost = -10000;
        for (int x = 0; x < w; x++) {
            if (placed[y][x] == 'X') leftmost = x;
            left[y][x] = leftmost;
        }
        int rightleast = +10000;
        for (int x = w - 1; x >= 0; x--) {
            if (placed[y][x] == 'X') rightleast = x;
            right[y][x] = rightleast;
        }
    }

    for (int x = 0; x < w; x++) {
        int topleast = -10000;
        for (int y = 0; y < h; y++) {
            if (placed[y][x] == 'X') topleast = y;
            top[y][x] = topleast;
        }
        int bottomleast = +10000;
        for (int y = h - 1; y >= 0; y--) {
            if (placed[y][x] == 'X') bottomleast = y;
            bottom[y][x] = bottomleast;
        }
    }

    vector<vector<vector<pair<int, int>>>> rel(h, vector<vector<pair<int, int>>>(w));

    int ds[] = {-1, +1};
    for (int y = 0; y < h; y++) {
        for (int x = 0; x < w; x++) {
            for (auto dy : ds) {
                if (y + dy < 0 || y + dy >= h) continue;
                int l = max(left[y][x], left[y + dy][x]);
                int r = min(right[y][x], right[y + dy][x]);

                if (r - l + 1 >= k) rel[y][x].push_back({y + dy, x});
            }

            for (auto dx : ds) {
                if (x + dx < 0 || x + dx >= w) continue;
                int u = max(up[y][x], up[y][x + dx]);
                int d = min(down[y][x], down[y][x + dx]);

                if (d - u + 1 >= l) rel[y][x].push_back({y, x + dx});
            }
        }
    }

    vector<vector<bool>> visited(h, vector<bool>(w, 0));
    deque<pair<int, int>> bfs;
    bfs.push_back({max(yh, yv), max(xh, xv)});

    while (!bfs.empty()) {
        auto [y, x] = bfs.front();
        bfs.pop_front();

        if (visited[y][x]) continue;
        visited[y][x] = 1;

        for (auto [ny, nx] : rel[y][x]) {
            bfs.push_back({ny, nx});
        }
    }

    cout << visited[desty][destx] << '\n';
}

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:48:13: error: 'top' was not declared in this scope
   48 |             top[y][x] = topleast;
      |             ^~~
Main.cpp:53:13: error: 'bottom' was not declared in this scope
   53 |             bottom[y][x] = bottomleast;
      |             ^~~~~~
Main.cpp:80:26: error: redeclaration of 'std::vector<std::vector<bool> > visited'
   80 |     vector<vector<bool>> visited(h, vector<bool>(w, 0));
      |                          ^~~~~~~
Main.cpp:25:26: note: 'std::vector<std::vector<bool> > visited' previously declared here
   25 |     vector<vector<bool>> visited(h, vector<bool>(w, 0));
      |                          ^~~~~~~