답안 #896641

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
896641 2024-01-01T20:00:47 Z arbuzick Maze (JOI23_ho_t3) C++17
43 / 100
2000 ms 700112 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() && 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() && 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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 860 KB Output is correct
2 Correct 1 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 3 ms 1368 KB Output is correct
6 Correct 2 ms 1372 KB Output is correct
7 Correct 2 ms 1372 KB Output is correct
8 Correct 2 ms 1372 KB Output is correct
9 Correct 0 ms 604 KB Output is correct
10 Correct 1 ms 860 KB Output is correct
11 Correct 0 ms 860 KB Output is correct
12 Correct 0 ms 604 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 856 KB Output is correct
16 Correct 3 ms 1372 KB Output is correct
17 Correct 4 ms 1372 KB Output is correct
18 Correct 2 ms 1372 KB Output is correct
19 Correct 202 ms 37460 KB Output is correct
20 Correct 119 ms 29268 KB Output is correct
21 Correct 166 ms 37516 KB Output is correct
22 Correct 193 ms 37456 KB Output is correct
23 Correct 220 ms 37468 KB Output is correct
24 Correct 154 ms 37880 KB Output is correct
25 Correct 158 ms 37976 KB Output is correct
26 Correct 222 ms 37772 KB Output is correct
27 Correct 203 ms 37464 KB Output is correct
28 Correct 198 ms 37456 KB Output is correct
29 Correct 550 ms 93348 KB Output is correct
30 Correct 169 ms 38632 KB Output is correct
31 Correct 464 ms 93268 KB Output is correct
32 Correct 585 ms 93268 KB Output is correct
33 Correct 648 ms 92956 KB Output is correct
34 Correct 455 ms 93616 KB Output is correct
35 Correct 439 ms 93620 KB Output is correct
36 Correct 569 ms 93008 KB Output is correct
37 Correct 625 ms 93052 KB Output is correct
38 Correct 579 ms 93076 KB Output is correct
39 Execution timed out 2074 ms 700112 KB Time limit exceeded
40 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 1 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 1368 KB Output is correct
6 Correct 0 ms 816 KB Output is correct
7 Correct 1 ms 856 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 1372 KB Output is correct
15 Correct 2 ms 1460 KB Output is correct
16 Correct 2 ms 1372 KB Output is correct
17 Correct 2 ms 1444 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 860 KB Output is correct
24 Correct 0 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 1112 KB Output is correct
28 Correct 2 ms 1112 KB Output is correct
29 Correct 1 ms 860 KB Output is correct
30 Correct 2 ms 1372 KB Output is correct
31 Correct 3 ms 1372 KB Output is correct
32 Correct 2 ms 1372 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 1 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 0 ms 604 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 1372 KB Output is correct
9 Correct 2 ms 1372 KB Output is correct
10 Correct 2 ms 1308 KB Output is correct
11 Correct 2 ms 1372 KB Output is correct
12 Correct 2 ms 1372 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 1116 KB Output is correct
17 Correct 1 ms 856 KB Output is correct
18 Correct 0 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 3 ms 1112 KB Output is correct
22 Correct 2 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 115 ms 24148 KB Output is correct
26 Correct 155 ms 33860 KB Output is correct
27 Correct 173 ms 37716 KB Output is correct
28 Correct 165 ms 38604 KB Output is correct
29 Correct 167 ms 38592 KB Output is correct
30 Correct 163 ms 38792 KB Output is correct
31 Correct 152 ms 37860 KB Output is correct
32 Correct 198 ms 37460 KB Output is correct
33 Correct 199 ms 37620 KB Output is correct
34 Correct 362 ms 75148 KB Output is correct
35 Correct 459 ms 93212 KB Output is correct
36 Correct 458 ms 97736 KB Output is correct
37 Correct 452 ms 98704 KB Output is correct
38 Correct 440 ms 98496 KB Output is correct
39 Correct 1501 ms 268444 KB Output is correct
40 Execution timed out 2047 ms 588496 KB Time limit exceeded
41 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 1 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 1368 KB Output is correct
6 Correct 0 ms 816 KB Output is correct
7 Correct 1 ms 856 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 1372 KB Output is correct
15 Correct 2 ms 1460 KB Output is correct
16 Correct 2 ms 1372 KB Output is correct
17 Correct 2 ms 1444 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 860 KB Output is correct
24 Correct 0 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 1112 KB Output is correct
28 Correct 2 ms 1112 KB Output is correct
29 Correct 1 ms 860 KB Output is correct
30 Correct 2 ms 1372 KB Output is correct
31 Correct 3 ms 1372 KB Output is correct
32 Correct 2 ms 1372 KB Output is correct
33 Correct 216 ms 37716 KB Output is correct
34 Correct 5 ms 2140 KB Output is correct
35 Correct 8 ms 3424 KB Output is correct
36 Correct 129 ms 23944 KB Output is correct
37 Correct 115 ms 29264 KB Output is correct
38 Correct 155 ms 34124 KB Output is correct
39 Correct 163 ms 37656 KB Output is correct
40 Correct 204 ms 37460 KB Output is correct
41 Correct 218 ms 37456 KB Output is correct
42 Correct 162 ms 38604 KB Output is correct
43 Correct 158 ms 38796 KB Output is correct
44 Correct 161 ms 38704 KB Output is correct
45 Correct 160 ms 37972 KB Output is correct
46 Correct 165 ms 37968 KB Output is correct
47 Correct 151 ms 37972 KB Output is correct
48 Correct 166 ms 37772 KB Output is correct
49 Correct 164 ms 37712 KB Output is correct
50 Correct 171 ms 37612 KB Output is correct
51 Correct 171 ms 37716 KB Output is correct
52 Correct 200 ms 37712 KB Output is correct
53 Correct 206 ms 37432 KB Output is correct
54 Correct 196 ms 37564 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 1 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 1368 KB Output is correct
6 Correct 0 ms 816 KB Output is correct
7 Correct 1 ms 856 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 1372 KB Output is correct
15 Correct 2 ms 1460 KB Output is correct
16 Correct 2 ms 1372 KB Output is correct
17 Correct 2 ms 1444 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 860 KB Output is correct
24 Correct 0 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 1112 KB Output is correct
28 Correct 2 ms 1112 KB Output is correct
29 Correct 1 ms 860 KB Output is correct
30 Correct 2 ms 1372 KB Output is correct
31 Correct 3 ms 1372 KB Output is correct
32 Correct 2 ms 1372 KB Output is correct
33 Correct 216 ms 37716 KB Output is correct
34 Correct 5 ms 2140 KB Output is correct
35 Correct 8 ms 3424 KB Output is correct
36 Correct 129 ms 23944 KB Output is correct
37 Correct 115 ms 29264 KB Output is correct
38 Correct 155 ms 34124 KB Output is correct
39 Correct 163 ms 37656 KB Output is correct
40 Correct 204 ms 37460 KB Output is correct
41 Correct 218 ms 37456 KB Output is correct
42 Correct 162 ms 38604 KB Output is correct
43 Correct 158 ms 38796 KB Output is correct
44 Correct 161 ms 38704 KB Output is correct
45 Correct 160 ms 37972 KB Output is correct
46 Correct 165 ms 37968 KB Output is correct
47 Correct 151 ms 37972 KB Output is correct
48 Correct 166 ms 37772 KB Output is correct
49 Correct 164 ms 37712 KB Output is correct
50 Correct 171 ms 37612 KB Output is correct
51 Correct 171 ms 37716 KB Output is correct
52 Correct 200 ms 37712 KB Output is correct
53 Correct 206 ms 37432 KB Output is correct
54 Correct 196 ms 37564 KB Output is correct
55 Correct 567 ms 93012 KB Output is correct
56 Correct 179 ms 38736 KB Output is correct
57 Correct 353 ms 75092 KB Output is correct
58 Correct 451 ms 85184 KB Output is correct
59 Correct 487 ms 93012 KB Output is correct
60 Correct 549 ms 93196 KB Output is correct
61 Correct 614 ms 93040 KB Output is correct
62 Correct 504 ms 97224 KB Output is correct
63 Correct 459 ms 99268 KB Output is correct
64 Correct 442 ms 98232 KB Output is correct
65 Correct 445 ms 93704 KB Output is correct
66 Correct 451 ms 93600 KB Output is correct
67 Correct 450 ms 93264 KB Output is correct
68 Correct 460 ms 93068 KB Output is correct
69 Correct 506 ms 93256 KB Output is correct
70 Correct 491 ms 93264 KB Output is correct
71 Correct 460 ms 93508 KB Output is correct
72 Correct 556 ms 93012 KB Output is correct
73 Correct 584 ms 93056 KB Output is correct
74 Correct 628 ms 93068 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 860 KB Output is correct
2 Correct 1 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 3 ms 1368 KB Output is correct
6 Correct 2 ms 1372 KB Output is correct
7 Correct 2 ms 1372 KB Output is correct
8 Correct 2 ms 1372 KB Output is correct
9 Correct 0 ms 604 KB Output is correct
10 Correct 1 ms 860 KB Output is correct
11 Correct 0 ms 860 KB Output is correct
12 Correct 0 ms 604 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 856 KB Output is correct
16 Correct 3 ms 1372 KB Output is correct
17 Correct 4 ms 1372 KB Output is correct
18 Correct 2 ms 1372 KB Output is correct
19 Correct 202 ms 37460 KB Output is correct
20 Correct 119 ms 29268 KB Output is correct
21 Correct 166 ms 37516 KB Output is correct
22 Correct 193 ms 37456 KB Output is correct
23 Correct 220 ms 37468 KB Output is correct
24 Correct 154 ms 37880 KB Output is correct
25 Correct 158 ms 37976 KB Output is correct
26 Correct 222 ms 37772 KB Output is correct
27 Correct 203 ms 37464 KB Output is correct
28 Correct 198 ms 37456 KB Output is correct
29 Correct 550 ms 93348 KB Output is correct
30 Correct 169 ms 38632 KB Output is correct
31 Correct 464 ms 93268 KB Output is correct
32 Correct 585 ms 93268 KB Output is correct
33 Correct 648 ms 92956 KB Output is correct
34 Correct 455 ms 93616 KB Output is correct
35 Correct 439 ms 93620 KB Output is correct
36 Correct 569 ms 93008 KB Output is correct
37 Correct 625 ms 93052 KB Output is correct
38 Correct 579 ms 93076 KB Output is correct
39 Execution timed out 2074 ms 700112 KB Time limit exceeded
40 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 860 KB Output is correct
2 Correct 1 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 3 ms 1368 KB Output is correct
6 Correct 2 ms 1372 KB Output is correct
7 Correct 2 ms 1372 KB Output is correct
8 Correct 2 ms 1372 KB Output is correct
9 Correct 0 ms 604 KB Output is correct
10 Correct 1 ms 860 KB Output is correct
11 Correct 0 ms 860 KB Output is correct
12 Correct 0 ms 604 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 856 KB Output is correct
16 Correct 3 ms 1372 KB Output is correct
17 Correct 4 ms 1372 KB Output is correct
18 Correct 2 ms 1372 KB Output is correct
19 Correct 202 ms 37460 KB Output is correct
20 Correct 119 ms 29268 KB Output is correct
21 Correct 166 ms 37516 KB Output is correct
22 Correct 193 ms 37456 KB Output is correct
23 Correct 220 ms 37468 KB Output is correct
24 Correct 154 ms 37880 KB Output is correct
25 Correct 158 ms 37976 KB Output is correct
26 Correct 222 ms 37772 KB Output is correct
27 Correct 203 ms 37464 KB Output is correct
28 Correct 198 ms 37456 KB Output is correct
29 Correct 550 ms 93348 KB Output is correct
30 Correct 169 ms 38632 KB Output is correct
31 Correct 464 ms 93268 KB Output is correct
32 Correct 585 ms 93268 KB Output is correct
33 Correct 648 ms 92956 KB Output is correct
34 Correct 455 ms 93616 KB Output is correct
35 Correct 439 ms 93620 KB Output is correct
36 Correct 569 ms 93008 KB Output is correct
37 Correct 625 ms 93052 KB Output is correct
38 Correct 579 ms 93076 KB Output is correct
39 Execution timed out 2074 ms 700112 KB Time limit exceeded
40 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 860 KB Output is correct
2 Correct 1 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 3 ms 1368 KB Output is correct
6 Correct 2 ms 1372 KB Output is correct
7 Correct 2 ms 1372 KB Output is correct
8 Correct 2 ms 1372 KB Output is correct
9 Correct 0 ms 604 KB Output is correct
10 Correct 1 ms 860 KB Output is correct
11 Correct 0 ms 860 KB Output is correct
12 Correct 0 ms 604 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 856 KB Output is correct
16 Correct 3 ms 1372 KB Output is correct
17 Correct 4 ms 1372 KB Output is correct
18 Correct 2 ms 1372 KB Output is correct
19 Correct 202 ms 37460 KB Output is correct
20 Correct 119 ms 29268 KB Output is correct
21 Correct 166 ms 37516 KB Output is correct
22 Correct 193 ms 37456 KB Output is correct
23 Correct 220 ms 37468 KB Output is correct
24 Correct 154 ms 37880 KB Output is correct
25 Correct 158 ms 37976 KB Output is correct
26 Correct 222 ms 37772 KB Output is correct
27 Correct 203 ms 37464 KB Output is correct
28 Correct 198 ms 37456 KB Output is correct
29 Correct 550 ms 93348 KB Output is correct
30 Correct 169 ms 38632 KB Output is correct
31 Correct 464 ms 93268 KB Output is correct
32 Correct 585 ms 93268 KB Output is correct
33 Correct 648 ms 92956 KB Output is correct
34 Correct 455 ms 93616 KB Output is correct
35 Correct 439 ms 93620 KB Output is correct
36 Correct 569 ms 93008 KB Output is correct
37 Correct 625 ms 93052 KB Output is correct
38 Correct 579 ms 93076 KB Output is correct
39 Execution timed out 2074 ms 700112 KB Time limit exceeded
40 Halted 0 ms 0 KB -