103132024-03-30 15:05:40MagyarKendeSZLGLabirintuscpp17Time limit exceeded 15/1002.099s54796 KiB
#include "labirintus.h"
#include <queue>
#include <array>

std::vector<std::vector<int>> l;
constexpr int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1};
int r, c;


void init_labyrinth(int R, int C, std::vector<std::vector<int>> L) {
    l = L;
    r = R;
    c = C;
}

bool can_escape(int N, std::vector<int> U, std::vector<int> V) {

    for (int i = 0; i < N; i++) {
        l[U[i]][V[i]] = 1;
    }

    std::vector<std::vector<bool>> vis(r, std::vector<bool>(c));
    std::queue<std::array<int, 2>> q({{0, 0}});
    vis[0][0] = 1;

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

        if (x == c - 1 && y == r - 1) {
            for (int i = 0; i < N; i++) {
                l[U[i]][V[i]] = 0;
            };
            return true;
        }

        for (int i = 0; i < 4; i++) {
            int nx = x + dx[i], ny = y + dy[i];
            if (nx < 0 || ny < 0 || nx >= c || ny >= r || l[ny][nx]) {
                continue;
            }
            if (!vis[ny][nx]) {
                vis[ny][nx] = 1;
                q.push({nx, ny});
            }
        }
    }

    for (int i = 0; i < N; i++) {
        l[U[i]][V[i]] = 0;
    }

    return false;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1480 KiB
2Time limit exceeded2.099s14040 KiB
subtask215/15
3Accepted54ms3892 KiB
4Accepted28ms4348 KiB
5Accepted108ms6784 KiB
6Accepted111ms9196 KiB
7Accepted68ms12016 KiB
8Accepted70ms14116 KiB
subtask30/18
9Time limit exceeded2.061s14372 KiB
10Accepted593ms17452 KiB
11Time limit exceeded2.066s29888 KiB
12Time limit exceeded2.072s30864 KiB
13Time limit exceeded2.072s32020 KiB
14Time limit exceeded2.069s32944 KiB
subtask40/28
15Accepted867ms49384 KiB
16Accepted773ms51648 KiB
17Accepted435ms52868 KiB
18Accepted358ms52876 KiB
19Time limit exceeded2.078s40840 KiB
20Accepted87ms52944 KiB
21Accepted138ms52900 KiB
22Time limit exceeded2.062s40852 KiB
23Time limit exceeded2.056s40836 KiB
subtask50/39
24Accepted37ms29688 KiB
25Accepted18ms29564 KiB
26Accepted108ms29828 KiB
27Accepted111ms29776 KiB
28Accepted108ms30076 KiB
29Accepted111ms29996 KiB
30Time limit exceeded2.075s41364 KiB
31Time limit exceeded2.053s41496 KiB
32Time limit exceeded2.072s41536 KiB
33Time limit exceeded2.065s41552 KiB
34Time limit exceeded2.069s41864 KiB
35Time limit exceeded2.065s41928 KiB
36Accepted228ms54224 KiB
37Accepted439ms54136 KiB
38Accepted188ms54672 KiB
39Accepted642ms54796 KiB