Submission #899415

# Submission time Handle Problem Language Result Execution time Memory
899415 2024-01-06T06:27:44 Z LiuBruh Maze (JOI23_ho_t3) C++17
8 / 100
815 ms 870832 KB
#include <bits/stdc++.h>

#define int long long
#define F first
#define S second
#define sz(v) (int)v.size()
using namespace std;

const int INF = (int)1e18 + 5;

const int dx[4] = {0, 0, 1, -1};
const int dy[4] = {1, -1, 0, 0};

int r, c, n;
int sx, sy, tx, ty;
vector<vector<int>> g, dis, vis;
vector<vector<vector<int>>> e;

bool out(int x, int y) {
    return min(x, y) < 1 or x > r or y > c;
}

void solve() {
    cin >> r >> c >> n >> sx >> sy >> tx >> ty;

    g = vector<vector<int>> (r + 5, vector<int> (c + 5));
    e = vector<vector<vector<int>>> (r + 5, vector<vector<int>> (c + 5, vector<int> (4)));
    dis = vector<vector<int>> (r + 5, vector<int> (c + 5));
    vis = vector<vector<int>> (r + 5, vector<int> (c + 5));

    for (int i = 1; i <= r; i++) {
        for (int j = 1; j <= c; j++) {
            char ch;  cin >> ch;
            g[i][j] = (ch == '.');
        }
    }
    for (int i = 1; i <= r; i++) {
        for (int j = 1; j <= c; j++) {
            int nx, ny;
            for (int k = 0; k < 4; k++) {
                nx = i + dx[k];
                ny = j + dy[k];
                if (!out(nx, ny)) {
                    e[i][j][k] = (g[nx][ny] == 0);
                }
            }
        }
    }

    deque<pair<pair<int, int>, int>> dq;
    dq.push_back({{sx, sy}, 0});
    vis[sx][sy] = true;

    while (!dq.empty()) {
        auto [coo, d] = dq.front();  dq.pop_front();
        auto [x, y] = coo;
        dis[x][y] = d;

        int nx, ny;
        for (int k = 0; k < 4; k++) {
            nx = x + dx[k], ny = y + dy[k];
            if (out(nx, ny) or vis[nx][ny]) continue;
            vis[nx][ny] = true;
            if (e[x][y][k] == 0) {
                dq.push_front({{nx, ny}, d});
            } else {
                dq.push_back({{nx, ny}, d + 1});
            }
        }
    }

    cout << dis[tx][ty] << '\n';
}

signed main() {
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);

    solve();

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 860 KB Output is correct
8 Correct 1 ms 860 KB Output is correct
9 Correct 0 ms 460 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 452 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 7 ms 6236 KB Output is correct
20 Correct 22 ms 27060 KB Output is correct
21 Correct 9 ms 6752 KB Output is correct
22 Correct 8 ms 6236 KB Output is correct
23 Correct 7 ms 6292 KB Output is correct
24 Correct 31 ms 35076 KB Output is correct
25 Correct 30 ms 35064 KB Output is correct
26 Correct 9 ms 6488 KB Output is correct
27 Correct 9 ms 6236 KB Output is correct
28 Correct 7 ms 6236 KB Output is correct
29 Correct 22 ms 15452 KB Output is correct
30 Correct 21 ms 21148 KB Output is correct
31 Correct 21 ms 15960 KB Output is correct
32 Correct 19 ms 14940 KB Output is correct
33 Correct 18 ms 14940 KB Output is correct
34 Correct 70 ms 87444 KB Output is correct
35 Correct 69 ms 87296 KB Output is correct
36 Correct 21 ms 15196 KB Output is correct
37 Correct 25 ms 15192 KB Output is correct
38 Correct 20 ms 14940 KB Output is correct
39 Correct 232 ms 144128 KB Output is correct
40 Correct 30 ms 21856 KB Output is correct
41 Correct 91 ms 107476 KB Output is correct
42 Correct 31 ms 21324 KB Output is correct
43 Correct 71 ms 82264 KB Output is correct
44 Correct 139 ms 131252 KB Output is correct
45 Correct 160 ms 154172 KB Output is correct
46 Correct 237 ms 149052 KB Output is correct
47 Correct 225 ms 144224 KB Output is correct
48 Correct 289 ms 144232 KB Output is correct
49 Correct 815 ms 870832 KB Output is correct
50 Correct 702 ms 870832 KB Output is correct
51 Correct 240 ms 144892 KB Output is correct
52 Correct 227 ms 144212 KB Output is correct
53 Correct 245 ms 144228 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 860 KB Output is correct
8 Correct 1 ms 860 KB Output is correct
9 Correct 0 ms 460 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 452 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 7 ms 6236 KB Output is correct
20 Correct 22 ms 27060 KB Output is correct
21 Correct 9 ms 6752 KB Output is correct
22 Correct 8 ms 6236 KB Output is correct
23 Correct 7 ms 6292 KB Output is correct
24 Correct 31 ms 35076 KB Output is correct
25 Correct 30 ms 35064 KB Output is correct
26 Correct 9 ms 6488 KB Output is correct
27 Correct 9 ms 6236 KB Output is correct
28 Correct 7 ms 6236 KB Output is correct
29 Correct 22 ms 15452 KB Output is correct
30 Correct 21 ms 21148 KB Output is correct
31 Correct 21 ms 15960 KB Output is correct
32 Correct 19 ms 14940 KB Output is correct
33 Correct 18 ms 14940 KB Output is correct
34 Correct 70 ms 87444 KB Output is correct
35 Correct 69 ms 87296 KB Output is correct
36 Correct 21 ms 15196 KB Output is correct
37 Correct 25 ms 15192 KB Output is correct
38 Correct 20 ms 14940 KB Output is correct
39 Correct 232 ms 144128 KB Output is correct
40 Correct 30 ms 21856 KB Output is correct
41 Correct 91 ms 107476 KB Output is correct
42 Correct 31 ms 21324 KB Output is correct
43 Correct 71 ms 82264 KB Output is correct
44 Correct 139 ms 131252 KB Output is correct
45 Correct 160 ms 154172 KB Output is correct
46 Correct 237 ms 149052 KB Output is correct
47 Correct 225 ms 144224 KB Output is correct
48 Correct 289 ms 144232 KB Output is correct
49 Correct 815 ms 870832 KB Output is correct
50 Correct 702 ms 870832 KB Output is correct
51 Correct 240 ms 144892 KB Output is correct
52 Correct 227 ms 144212 KB Output is correct
53 Correct 245 ms 144228 KB Output is correct
54 Incorrect 0 ms 344 KB Output isn't correct
55 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 860 KB Output is correct
8 Correct 1 ms 860 KB Output is correct
9 Correct 0 ms 460 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 452 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 7 ms 6236 KB Output is correct
20 Correct 22 ms 27060 KB Output is correct
21 Correct 9 ms 6752 KB Output is correct
22 Correct 8 ms 6236 KB Output is correct
23 Correct 7 ms 6292 KB Output is correct
24 Correct 31 ms 35076 KB Output is correct
25 Correct 30 ms 35064 KB Output is correct
26 Correct 9 ms 6488 KB Output is correct
27 Correct 9 ms 6236 KB Output is correct
28 Correct 7 ms 6236 KB Output is correct
29 Correct 22 ms 15452 KB Output is correct
30 Correct 21 ms 21148 KB Output is correct
31 Correct 21 ms 15960 KB Output is correct
32 Correct 19 ms 14940 KB Output is correct
33 Correct 18 ms 14940 KB Output is correct
34 Correct 70 ms 87444 KB Output is correct
35 Correct 69 ms 87296 KB Output is correct
36 Correct 21 ms 15196 KB Output is correct
37 Correct 25 ms 15192 KB Output is correct
38 Correct 20 ms 14940 KB Output is correct
39 Correct 232 ms 144128 KB Output is correct
40 Correct 30 ms 21856 KB Output is correct
41 Correct 91 ms 107476 KB Output is correct
42 Correct 31 ms 21324 KB Output is correct
43 Correct 71 ms 82264 KB Output is correct
44 Correct 139 ms 131252 KB Output is correct
45 Correct 160 ms 154172 KB Output is correct
46 Correct 237 ms 149052 KB Output is correct
47 Correct 225 ms 144224 KB Output is correct
48 Correct 289 ms 144232 KB Output is correct
49 Correct 815 ms 870832 KB Output is correct
50 Correct 702 ms 870832 KB Output is correct
51 Correct 240 ms 144892 KB Output is correct
52 Correct 227 ms 144212 KB Output is correct
53 Correct 245 ms 144228 KB Output is correct
54 Incorrect 0 ms 344 KB Output isn't correct
55 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 860 KB Output is correct
8 Correct 1 ms 860 KB Output is correct
9 Correct 0 ms 460 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 452 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 7 ms 6236 KB Output is correct
20 Correct 22 ms 27060 KB Output is correct
21 Correct 9 ms 6752 KB Output is correct
22 Correct 8 ms 6236 KB Output is correct
23 Correct 7 ms 6292 KB Output is correct
24 Correct 31 ms 35076 KB Output is correct
25 Correct 30 ms 35064 KB Output is correct
26 Correct 9 ms 6488 KB Output is correct
27 Correct 9 ms 6236 KB Output is correct
28 Correct 7 ms 6236 KB Output is correct
29 Correct 22 ms 15452 KB Output is correct
30 Correct 21 ms 21148 KB Output is correct
31 Correct 21 ms 15960 KB Output is correct
32 Correct 19 ms 14940 KB Output is correct
33 Correct 18 ms 14940 KB Output is correct
34 Correct 70 ms 87444 KB Output is correct
35 Correct 69 ms 87296 KB Output is correct
36 Correct 21 ms 15196 KB Output is correct
37 Correct 25 ms 15192 KB Output is correct
38 Correct 20 ms 14940 KB Output is correct
39 Correct 232 ms 144128 KB Output is correct
40 Correct 30 ms 21856 KB Output is correct
41 Correct 91 ms 107476 KB Output is correct
42 Correct 31 ms 21324 KB Output is correct
43 Correct 71 ms 82264 KB Output is correct
44 Correct 139 ms 131252 KB Output is correct
45 Correct 160 ms 154172 KB Output is correct
46 Correct 237 ms 149052 KB Output is correct
47 Correct 225 ms 144224 KB Output is correct
48 Correct 289 ms 144232 KB Output is correct
49 Correct 815 ms 870832 KB Output is correct
50 Correct 702 ms 870832 KB Output is correct
51 Correct 240 ms 144892 KB Output is correct
52 Correct 227 ms 144212 KB Output is correct
53 Correct 245 ms 144228 KB Output is correct
54 Incorrect 0 ms 344 KB Output isn't correct
55 Halted 0 ms 0 KB -