Submission #896640

# Submission time Handle Problem Language Result Execution time Memory
896640 2024-01-01T19:59:28 Z arbuzick Maze (JOI23_ho_t3) C++17
43 / 100
2000 ms 668856 KB
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2")
#include <bits/stdc++.h>

using namespace std;

constexpr int R = 1 << 12;

set<pair<int, int>> tree[R * 2];

void add(int pos, pair<int, int> val) {
    for (pos += R; pos > 0; pos /= 2) {
        tree[pos].insert(val);
    }
}

void del(int pos, pair<int, int> val) {
    for (pos += R; pos > 0; pos /= 2) {
        tree[pos].erase(val);
    }
}

vector<pair<int, int>> vals;

void get_vals(int l, int r, int x, int y) {
    l = max(l, 0);
    r = min(r, R);
    l += R;
    r += R;
    while (l < r) {
        if (l & 1) {
            auto it = tree[l].lower_bound({x, 0});
            while (it != tree[l].end() && x <= it->first && it->first < y) {
                vals.push_back(*it);
                it++;
            }
            l++;
        }
        if (r & 1) {
            --r;
            auto it = tree[r].lower_bound({x, 0});
            while (it != tree[r].end() && x <= it->first && it->first < y) {
                vals.push_back(*it);
                it++;
            }
        }
        l >>= 1;
        r >>= 1;
    }
}

void solve() {
    int r, c, n;
    cin >> r >> c >> n;
    int sx, sy;
    cin >> sx >> sy;
    sx--, sy--;
    int gx, gy;
    cin >> gx >> gy;
    gx--, gy--;
    vector<string> a(r);
    for (int i = 0; i < r; ++i) {
        cin >> a[i];
    }
    for (int i = 0; i < r; ++i) {
        for (int j = 0; j < c; ++j) {
            add(i, {j, i});
        }
    }
    vector<vector<int>> dp(r, vector<int>(c, r * c));
    deque<pair<int, int>> dq;
    dp[sx][sy] = 0;
    del(sx, {sy, sx});
    dq.push_back({sx, sy});
    set<pair<int, int>> used;
    while (!dq.empty()) {
        auto [x, y] = dq.front();
        dq.pop_front();
        if (used.count({x, y})) {
            continue;
        }
        used.insert({x, y});
        if (x > 0 && a[x - 1][y] == '.' && dp[x - 1][y] > dp[x][y]) {
            if (dp[x - 1][y] == r * c) {
                del(x - 1, {y, x - 1});
            }
            dp[x - 1][y] = dp[x][y];
            dq.push_front({x - 1, y});
        }
        if (x + 1 < r && a[x + 1][y] == '.' && dp[x + 1][y] > dp[x][y]) {
            if (dp[x + 1][y] == r * c) {
                del(x + 1, {y, x + 1});
            }
            dp[x + 1][y] = dp[x][y];
            dq.push_front({x + 1, y});
        }
        if (y > 0 && a[x][y - 1] == '.' && dp[x][y - 1] > dp[x][y]) {
            if (dp[x][y - 1] == r * c) {
                del(x, {y - 1, x});
            }
            dp[x][y - 1] = dp[x][y];
            dq.push_front({x, y - 1});
        }
        if (y + 1 < c && a[x][y + 1] == '.' && dp[x][y + 1] > dp[x][y]) {
            if (dp[x][y + 1] == r * c) {
                del(x, {y + 1, x});
            }
            dp[x][y + 1] = dp[x][y];
            dq.push_front({x, y + 1});
        }
        get_vals(x - n + 1, x + n, y - n, y + n + 1);
        get_vals(x - n, x + n + 1, y - n + 1, y + n);
        for (auto p : vals) {
            if (dp[p.second][p.first] != r * c) {
                continue;
            }
            del(p.second, p);
            swap(p.first, p.second);
            dp[p.first][p.second] = dp[x][y] + 1;
            dq.push_back(p);
        }
        vals.clear();
    }
    cout << dp[gx][gy] << '\n';
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int t = 1;
    // cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 860 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Correct 2 ms 1372 KB Output is correct
4 Correct 2 ms 1372 KB Output is correct
5 Correct 2 ms 1372 KB Output is correct
6 Correct 3 ms 1372 KB Output is correct
7 Correct 2 ms 1372 KB Output is correct
8 Correct 2 ms 1368 KB Output is correct
9 Correct 0 ms 604 KB Output is correct
10 Correct 0 ms 860 KB Output is correct
11 Correct 0 ms 860 KB Output is correct
12 Correct 1 ms 600 KB Output is correct
13 Correct 1 ms 860 KB Output is correct
14 Correct 1 ms 860 KB Output is correct
15 Correct 1 ms 860 KB Output is correct
16 Correct 2 ms 1372 KB Output is correct
17 Correct 3 ms 1372 KB Output is correct
18 Correct 3 ms 1372 KB Output is correct
19 Correct 207 ms 37556 KB Output is correct
20 Correct 145 ms 29260 KB Output is correct
21 Correct 171 ms 37712 KB Output is correct
22 Correct 193 ms 37448 KB Output is correct
23 Correct 218 ms 37456 KB Output is correct
24 Correct 161 ms 37968 KB Output is correct
25 Correct 160 ms 37972 KB Output is correct
26 Correct 203 ms 37656 KB Output is correct
27 Correct 200 ms 37660 KB Output is correct
28 Correct 247 ms 37468 KB Output is correct
29 Correct 551 ms 93036 KB Output is correct
30 Correct 169 ms 38480 KB Output is correct
31 Correct 462 ms 92864 KB Output is correct
32 Correct 542 ms 92824 KB Output is correct
33 Correct 601 ms 93156 KB Output is correct
34 Correct 447 ms 93660 KB Output is correct
35 Correct 435 ms 93660 KB Output is correct
36 Correct 593 ms 92876 KB Output is correct
37 Correct 580 ms 93060 KB Output is correct
38 Correct 611 ms 93044 KB Output is correct
39 Execution timed out 2086 ms 668856 KB Time limit exceeded
40 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 0 ms 860 KB Output is correct
3 Correct 1 ms 860 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 2 ms 1372 KB Output is correct
6 Correct 0 ms 604 KB Output is correct
7 Correct 1 ms 860 KB Output is correct
8 Correct 1 ms 860 KB Output is correct
9 Correct 2 ms 1372 KB Output is correct
10 Correct 3 ms 1372 KB Output is correct
11 Correct 3 ms 1372 KB Output is correct
12 Correct 2 ms 1372 KB Output is correct
13 Correct 2 ms 1484 KB Output is correct
14 Correct 2 ms 1368 KB Output is correct
15 Correct 2 ms 1468 KB Output is correct
16 Correct 2 ms 1372 KB Output is correct
17 Correct 2 ms 1372 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 2 ms 1116 KB Output is correct
20 Correct 1 ms 860 KB Output is correct
21 Correct 1 ms 860 KB Output is correct
22 Correct 2 ms 1116 KB Output is correct
23 Correct 1 ms 856 KB Output is correct
24 Correct 1 ms 860 KB Output is correct
25 Correct 1 ms 604 KB Output is correct
26 Correct 1 ms 860 KB Output is correct
27 Correct 1 ms 860 KB Output is correct
28 Correct 2 ms 1116 KB Output is correct
29 Correct 0 ms 860 KB Output is correct
30 Correct 2 ms 1372 KB Output is correct
31 Correct 2 ms 1372 KB Output is correct
32 Correct 3 ms 1372 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 0 ms 860 KB Output is correct
3 Correct 1 ms 860 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 1 ms 600 KB Output is correct
6 Correct 1 ms 860 KB Output is correct
7 Correct 2 ms 1372 KB Output is correct
8 Correct 2 ms 1452 KB Output is correct
9 Correct 2 ms 1372 KB Output is correct
10 Correct 2 ms 1372 KB Output is correct
11 Correct 2 ms 1372 KB Output is correct
12 Correct 3 ms 1572 KB Output is correct
13 Correct 0 ms 604 KB Output is correct
14 Correct 2 ms 1116 KB Output is correct
15 Correct 1 ms 860 KB Output is correct
16 Correct 2 ms 1112 KB Output is correct
17 Correct 1 ms 860 KB Output is correct
18 Correct 1 ms 860 KB Output is correct
19 Correct 0 ms 604 KB Output is correct
20 Correct 1 ms 860 KB Output is correct
21 Correct 2 ms 1116 KB Output is correct
22 Correct 3 ms 1372 KB Output is correct
23 Correct 2 ms 1372 KB Output is correct
24 Correct 5 ms 2140 KB Output is correct
25 Correct 117 ms 24188 KB Output is correct
26 Correct 158 ms 33920 KB Output is correct
27 Correct 176 ms 37656 KB Output is correct
28 Correct 168 ms 38600 KB Output is correct
29 Correct 157 ms 38604 KB Output is correct
30 Correct 154 ms 38600 KB Output is correct
31 Correct 149 ms 37720 KB Output is correct
32 Correct 204 ms 37456 KB Output is correct
33 Correct 210 ms 37452 KB Output is correct
34 Correct 358 ms 75192 KB Output is correct
35 Correct 477 ms 93060 KB Output is correct
36 Correct 451 ms 97880 KB Output is correct
37 Correct 447 ms 97756 KB Output is correct
38 Correct 441 ms 97732 KB Output is correct
39 Correct 1490 ms 268436 KB Output is correct
40 Execution timed out 2097 ms 588908 KB Time limit exceeded
41 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 0 ms 860 KB Output is correct
3 Correct 1 ms 860 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 2 ms 1372 KB Output is correct
6 Correct 0 ms 604 KB Output is correct
7 Correct 1 ms 860 KB Output is correct
8 Correct 1 ms 860 KB Output is correct
9 Correct 2 ms 1372 KB Output is correct
10 Correct 3 ms 1372 KB Output is correct
11 Correct 3 ms 1372 KB Output is correct
12 Correct 2 ms 1372 KB Output is correct
13 Correct 2 ms 1484 KB Output is correct
14 Correct 2 ms 1368 KB Output is correct
15 Correct 2 ms 1468 KB Output is correct
16 Correct 2 ms 1372 KB Output is correct
17 Correct 2 ms 1372 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 2 ms 1116 KB Output is correct
20 Correct 1 ms 860 KB Output is correct
21 Correct 1 ms 860 KB Output is correct
22 Correct 2 ms 1116 KB Output is correct
23 Correct 1 ms 856 KB Output is correct
24 Correct 1 ms 860 KB Output is correct
25 Correct 1 ms 604 KB Output is correct
26 Correct 1 ms 860 KB Output is correct
27 Correct 1 ms 860 KB Output is correct
28 Correct 2 ms 1116 KB Output is correct
29 Correct 0 ms 860 KB Output is correct
30 Correct 2 ms 1372 KB Output is correct
31 Correct 2 ms 1372 KB Output is correct
32 Correct 3 ms 1372 KB Output is correct
33 Correct 210 ms 37720 KB Output is correct
34 Correct 5 ms 2140 KB Output is correct
35 Correct 8 ms 3456 KB Output is correct
36 Correct 113 ms 24176 KB Output is correct
37 Correct 116 ms 29264 KB Output is correct
38 Correct 188 ms 33876 KB Output is correct
39 Correct 164 ms 37664 KB Output is correct
40 Correct 194 ms 37456 KB Output is correct
41 Correct 222 ms 37456 KB Output is correct
42 Correct 166 ms 38728 KB Output is correct
43 Correct 160 ms 38744 KB Output is correct
44 Correct 153 ms 38600 KB Output is correct
45 Correct 163 ms 37968 KB Output is correct
46 Correct 159 ms 37968 KB Output is correct
47 Correct 158 ms 38020 KB Output is correct
48 Correct 167 ms 37744 KB Output is correct
49 Correct 166 ms 37712 KB Output is correct
50 Correct 147 ms 37580 KB Output is correct
51 Correct 159 ms 37712 KB Output is correct
52 Correct 198 ms 37456 KB Output is correct
53 Correct 227 ms 37580 KB Output is correct
54 Correct 200 ms 37456 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 0 ms 860 KB Output is correct
3 Correct 1 ms 860 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 2 ms 1372 KB Output is correct
6 Correct 0 ms 604 KB Output is correct
7 Correct 1 ms 860 KB Output is correct
8 Correct 1 ms 860 KB Output is correct
9 Correct 2 ms 1372 KB Output is correct
10 Correct 3 ms 1372 KB Output is correct
11 Correct 3 ms 1372 KB Output is correct
12 Correct 2 ms 1372 KB Output is correct
13 Correct 2 ms 1484 KB Output is correct
14 Correct 2 ms 1368 KB Output is correct
15 Correct 2 ms 1468 KB Output is correct
16 Correct 2 ms 1372 KB Output is correct
17 Correct 2 ms 1372 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 2 ms 1116 KB Output is correct
20 Correct 1 ms 860 KB Output is correct
21 Correct 1 ms 860 KB Output is correct
22 Correct 2 ms 1116 KB Output is correct
23 Correct 1 ms 856 KB Output is correct
24 Correct 1 ms 860 KB Output is correct
25 Correct 1 ms 604 KB Output is correct
26 Correct 1 ms 860 KB Output is correct
27 Correct 1 ms 860 KB Output is correct
28 Correct 2 ms 1116 KB Output is correct
29 Correct 0 ms 860 KB Output is correct
30 Correct 2 ms 1372 KB Output is correct
31 Correct 2 ms 1372 KB Output is correct
32 Correct 3 ms 1372 KB Output is correct
33 Correct 210 ms 37720 KB Output is correct
34 Correct 5 ms 2140 KB Output is correct
35 Correct 8 ms 3456 KB Output is correct
36 Correct 113 ms 24176 KB Output is correct
37 Correct 116 ms 29264 KB Output is correct
38 Correct 188 ms 33876 KB Output is correct
39 Correct 164 ms 37664 KB Output is correct
40 Correct 194 ms 37456 KB Output is correct
41 Correct 222 ms 37456 KB Output is correct
42 Correct 166 ms 38728 KB Output is correct
43 Correct 160 ms 38744 KB Output is correct
44 Correct 153 ms 38600 KB Output is correct
45 Correct 163 ms 37968 KB Output is correct
46 Correct 159 ms 37968 KB Output is correct
47 Correct 158 ms 38020 KB Output is correct
48 Correct 167 ms 37744 KB Output is correct
49 Correct 166 ms 37712 KB Output is correct
50 Correct 147 ms 37580 KB Output is correct
51 Correct 159 ms 37712 KB Output is correct
52 Correct 198 ms 37456 KB Output is correct
53 Correct 227 ms 37580 KB Output is correct
54 Correct 200 ms 37456 KB Output is correct
55 Correct 558 ms 93096 KB Output is correct
56 Correct 174 ms 38728 KB Output is correct
57 Correct 360 ms 75068 KB Output is correct
58 Correct 446 ms 84988 KB Output is correct
59 Correct 468 ms 92948 KB Output is correct
60 Correct 566 ms 93052 KB Output is correct
61 Correct 605 ms 93008 KB Output is correct
62 Correct 447 ms 99008 KB Output is correct
63 Correct 433 ms 98632 KB Output is correct
64 Correct 444 ms 97696 KB Output is correct
65 Correct 450 ms 93716 KB Output is correct
66 Correct 446 ms 93660 KB Output is correct
67 Correct 499 ms 93352 KB Output is correct
68 Correct 464 ms 93448 KB Output is correct
69 Correct 464 ms 93232 KB Output is correct
70 Correct 491 ms 93396 KB Output is correct
71 Correct 484 ms 93524 KB Output is correct
72 Correct 576 ms 92848 KB Output is correct
73 Correct 597 ms 93008 KB Output is correct
74 Correct 572 ms 93264 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 860 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Correct 2 ms 1372 KB Output is correct
4 Correct 2 ms 1372 KB Output is correct
5 Correct 2 ms 1372 KB Output is correct
6 Correct 3 ms 1372 KB Output is correct
7 Correct 2 ms 1372 KB Output is correct
8 Correct 2 ms 1368 KB Output is correct
9 Correct 0 ms 604 KB Output is correct
10 Correct 0 ms 860 KB Output is correct
11 Correct 0 ms 860 KB Output is correct
12 Correct 1 ms 600 KB Output is correct
13 Correct 1 ms 860 KB Output is correct
14 Correct 1 ms 860 KB Output is correct
15 Correct 1 ms 860 KB Output is correct
16 Correct 2 ms 1372 KB Output is correct
17 Correct 3 ms 1372 KB Output is correct
18 Correct 3 ms 1372 KB Output is correct
19 Correct 207 ms 37556 KB Output is correct
20 Correct 145 ms 29260 KB Output is correct
21 Correct 171 ms 37712 KB Output is correct
22 Correct 193 ms 37448 KB Output is correct
23 Correct 218 ms 37456 KB Output is correct
24 Correct 161 ms 37968 KB Output is correct
25 Correct 160 ms 37972 KB Output is correct
26 Correct 203 ms 37656 KB Output is correct
27 Correct 200 ms 37660 KB Output is correct
28 Correct 247 ms 37468 KB Output is correct
29 Correct 551 ms 93036 KB Output is correct
30 Correct 169 ms 38480 KB Output is correct
31 Correct 462 ms 92864 KB Output is correct
32 Correct 542 ms 92824 KB Output is correct
33 Correct 601 ms 93156 KB Output is correct
34 Correct 447 ms 93660 KB Output is correct
35 Correct 435 ms 93660 KB Output is correct
36 Correct 593 ms 92876 KB Output is correct
37 Correct 580 ms 93060 KB Output is correct
38 Correct 611 ms 93044 KB Output is correct
39 Execution timed out 2086 ms 668856 KB Time limit exceeded
40 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 860 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Correct 2 ms 1372 KB Output is correct
4 Correct 2 ms 1372 KB Output is correct
5 Correct 2 ms 1372 KB Output is correct
6 Correct 3 ms 1372 KB Output is correct
7 Correct 2 ms 1372 KB Output is correct
8 Correct 2 ms 1368 KB Output is correct
9 Correct 0 ms 604 KB Output is correct
10 Correct 0 ms 860 KB Output is correct
11 Correct 0 ms 860 KB Output is correct
12 Correct 1 ms 600 KB Output is correct
13 Correct 1 ms 860 KB Output is correct
14 Correct 1 ms 860 KB Output is correct
15 Correct 1 ms 860 KB Output is correct
16 Correct 2 ms 1372 KB Output is correct
17 Correct 3 ms 1372 KB Output is correct
18 Correct 3 ms 1372 KB Output is correct
19 Correct 207 ms 37556 KB Output is correct
20 Correct 145 ms 29260 KB Output is correct
21 Correct 171 ms 37712 KB Output is correct
22 Correct 193 ms 37448 KB Output is correct
23 Correct 218 ms 37456 KB Output is correct
24 Correct 161 ms 37968 KB Output is correct
25 Correct 160 ms 37972 KB Output is correct
26 Correct 203 ms 37656 KB Output is correct
27 Correct 200 ms 37660 KB Output is correct
28 Correct 247 ms 37468 KB Output is correct
29 Correct 551 ms 93036 KB Output is correct
30 Correct 169 ms 38480 KB Output is correct
31 Correct 462 ms 92864 KB Output is correct
32 Correct 542 ms 92824 KB Output is correct
33 Correct 601 ms 93156 KB Output is correct
34 Correct 447 ms 93660 KB Output is correct
35 Correct 435 ms 93660 KB Output is correct
36 Correct 593 ms 92876 KB Output is correct
37 Correct 580 ms 93060 KB Output is correct
38 Correct 611 ms 93044 KB Output is correct
39 Execution timed out 2086 ms 668856 KB Time limit exceeded
40 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 860 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Correct 2 ms 1372 KB Output is correct
4 Correct 2 ms 1372 KB Output is correct
5 Correct 2 ms 1372 KB Output is correct
6 Correct 3 ms 1372 KB Output is correct
7 Correct 2 ms 1372 KB Output is correct
8 Correct 2 ms 1368 KB Output is correct
9 Correct 0 ms 604 KB Output is correct
10 Correct 0 ms 860 KB Output is correct
11 Correct 0 ms 860 KB Output is correct
12 Correct 1 ms 600 KB Output is correct
13 Correct 1 ms 860 KB Output is correct
14 Correct 1 ms 860 KB Output is correct
15 Correct 1 ms 860 KB Output is correct
16 Correct 2 ms 1372 KB Output is correct
17 Correct 3 ms 1372 KB Output is correct
18 Correct 3 ms 1372 KB Output is correct
19 Correct 207 ms 37556 KB Output is correct
20 Correct 145 ms 29260 KB Output is correct
21 Correct 171 ms 37712 KB Output is correct
22 Correct 193 ms 37448 KB Output is correct
23 Correct 218 ms 37456 KB Output is correct
24 Correct 161 ms 37968 KB Output is correct
25 Correct 160 ms 37972 KB Output is correct
26 Correct 203 ms 37656 KB Output is correct
27 Correct 200 ms 37660 KB Output is correct
28 Correct 247 ms 37468 KB Output is correct
29 Correct 551 ms 93036 KB Output is correct
30 Correct 169 ms 38480 KB Output is correct
31 Correct 462 ms 92864 KB Output is correct
32 Correct 542 ms 92824 KB Output is correct
33 Correct 601 ms 93156 KB Output is correct
34 Correct 447 ms 93660 KB Output is correct
35 Correct 435 ms 93660 KB Output is correct
36 Correct 593 ms 92876 KB Output is correct
37 Correct 580 ms 93060 KB Output is correct
38 Correct 611 ms 93044 KB Output is correct
39 Execution timed out 2086 ms 668856 KB Time limit exceeded
40 Halted 0 ms 0 KB -