답안 #896637

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
896637 2024-01-01T19:54:11 Z arbuzick Maze (JOI23_ho_t3) C++17
43 / 100
2000 ms 705796 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);
    }
}

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

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});
        }
        while (true) {
            auto p = get_val(x - n + 1, x + n, y - n, y + n + 1);
            if (p.first == -1) {
                break;
            }
            del(p.second, p);
            swap(p.first, p.second);
            dp[p.first][p.second] = dp[x][y] + 1;
            dq.push_back(p);
        }
        while (true) {
            auto p = get_val(x - n, x + n + 1, y - n + 1, y + n);
            if (p.first == -1) {
                break;
            }
            del(p.second, p);
            swap(p.first, p.second);
            dp[p.first][p.second] = dp[x][y] + 1;
            dq.push_back(p);
        }
    }
    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 856 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 1460 KB Output is correct
5 Correct 3 ms 1372 KB Output is correct
6 Correct 3 ms 1372 KB Output is correct
7 Correct 3 ms 1368 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 948 KB Output is correct
15 Correct 1 ms 1112 KB Output is correct
16 Correct 2 ms 1372 KB Output is correct
17 Correct 3 ms 1368 KB Output is correct
18 Correct 4 ms 1372 KB Output is correct
19 Correct 211 ms 37492 KB Output is correct
20 Correct 116 ms 29264 KB Output is correct
21 Correct 165 ms 37716 KB Output is correct
22 Correct 206 ms 37600 KB Output is correct
23 Correct 223 ms 37712 KB Output is correct
24 Correct 177 ms 37852 KB Output is correct
25 Correct 155 ms 37968 KB Output is correct
26 Correct 200 ms 37712 KB Output is correct
27 Correct 215 ms 37716 KB Output is correct
28 Correct 196 ms 37464 KB Output is correct
29 Correct 555 ms 93184 KB Output is correct
30 Correct 166 ms 38740 KB Output is correct
31 Correct 464 ms 93016 KB Output is correct
32 Correct 557 ms 93012 KB Output is correct
33 Correct 607 ms 93188 KB Output is correct
34 Correct 447 ms 94036 KB Output is correct
35 Correct 446 ms 93832 KB Output is correct
36 Correct 593 ms 93008 KB Output is correct
37 Correct 589 ms 93540 KB Output is correct
38 Correct 644 ms 93192 KB Output is correct
39 Execution timed out 2065 ms 705796 KB Time limit exceeded
40 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 1 ms 860 KB Output is correct
3 Correct 1 ms 1108 KB Output is correct
4 Correct 0 ms 604 KB Output is correct
5 Correct 3 ms 1372 KB Output is correct
6 Correct 0 ms 604 KB Output is correct
7 Correct 1 ms 1016 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 1448 KB Output is correct
14 Correct 2 ms 1372 KB Output is correct
15 Correct 2 ms 1356 KB Output is correct
16 Correct 2 ms 1368 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 860 KB Output is correct
24 Correct 1 ms 860 KB Output is correct
25 Correct 0 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 1 ms 860 KB Output is correct
30 Correct 3 ms 1372 KB Output is correct
31 Correct 3 ms 1624 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 856 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 1 ms 860 KB Output is correct
6 Correct 1 ms 860 KB Output is correct
7 Correct 2 ms 1304 KB Output is correct
8 Correct 3 ms 1372 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 1360 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 840 KB Output is correct
16 Correct 2 ms 1116 KB Output is correct
17 Correct 1 ms 860 KB Output is correct
18 Correct 1 ms 860 KB Output is correct
19 Correct 1 ms 756 KB Output is correct
20 Correct 1 ms 860 KB Output is correct
21 Correct 2 ms 1124 KB Output is correct
22 Correct 3 ms 1376 KB Output is correct
23 Correct 3 ms 1456 KB Output is correct
24 Correct 5 ms 2148 KB Output is correct
25 Correct 128 ms 24148 KB Output is correct
26 Correct 151 ms 33872 KB Output is correct
27 Correct 162 ms 37620 KB Output is correct
28 Correct 159 ms 37716 KB Output is correct
29 Correct 152 ms 37712 KB Output is correct
30 Correct 156 ms 37932 KB Output is correct
31 Correct 157 ms 37740 KB Output is correct
32 Correct 201 ms 37720 KB Output is correct
33 Correct 202 ms 37716 KB Output is correct
34 Correct 360 ms 74836 KB Output is correct
35 Correct 482 ms 93304 KB Output is correct
36 Correct 419 ms 93016 KB Output is correct
37 Correct 412 ms 93008 KB Output is correct
38 Correct 411 ms 93128 KB Output is correct
39 Correct 1508 ms 268780 KB Output is correct
40 Execution timed out 2040 ms 583508 KB Time limit exceeded
41 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 1 ms 860 KB Output is correct
3 Correct 1 ms 1108 KB Output is correct
4 Correct 0 ms 604 KB Output is correct
5 Correct 3 ms 1372 KB Output is correct
6 Correct 0 ms 604 KB Output is correct
7 Correct 1 ms 1016 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 1448 KB Output is correct
14 Correct 2 ms 1372 KB Output is correct
15 Correct 2 ms 1356 KB Output is correct
16 Correct 2 ms 1368 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 860 KB Output is correct
24 Correct 1 ms 860 KB Output is correct
25 Correct 0 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 1 ms 860 KB Output is correct
30 Correct 3 ms 1372 KB Output is correct
31 Correct 3 ms 1624 KB Output is correct
32 Correct 2 ms 1372 KB Output is correct
33 Correct 211 ms 37716 KB Output is correct
34 Correct 5 ms 2140 KB Output is correct
35 Correct 8 ms 3612 KB Output is correct
36 Correct 114 ms 24024 KB Output is correct
37 Correct 118 ms 29268 KB Output is correct
38 Correct 156 ms 34072 KB Output is correct
39 Correct 162 ms 37724 KB Output is correct
40 Correct 234 ms 37700 KB Output is correct
41 Correct 229 ms 37692 KB Output is correct
42 Correct 171 ms 37712 KB Output is correct
43 Correct 149 ms 37716 KB Output is correct
44 Correct 153 ms 37720 KB Output is correct
45 Correct 162 ms 37968 KB Output is correct
46 Correct 155 ms 37912 KB Output is correct
47 Correct 153 ms 37716 KB Output is correct
48 Correct 175 ms 37820 KB Output is correct
49 Correct 173 ms 37832 KB Output is correct
50 Correct 152 ms 37652 KB Output is correct
51 Correct 159 ms 37712 KB Output is correct
52 Correct 198 ms 37660 KB Output is correct
53 Correct 205 ms 37712 KB Output is correct
54 Correct 195 ms 37708 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 1108 KB Output is correct
4 Correct 0 ms 604 KB Output is correct
5 Correct 3 ms 1372 KB Output is correct
6 Correct 0 ms 604 KB Output is correct
7 Correct 1 ms 1016 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 1448 KB Output is correct
14 Correct 2 ms 1372 KB Output is correct
15 Correct 2 ms 1356 KB Output is correct
16 Correct 2 ms 1368 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 860 KB Output is correct
24 Correct 1 ms 860 KB Output is correct
25 Correct 0 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 1 ms 860 KB Output is correct
30 Correct 3 ms 1372 KB Output is correct
31 Correct 3 ms 1624 KB Output is correct
32 Correct 2 ms 1372 KB Output is correct
33 Correct 211 ms 37716 KB Output is correct
34 Correct 5 ms 2140 KB Output is correct
35 Correct 8 ms 3612 KB Output is correct
36 Correct 114 ms 24024 KB Output is correct
37 Correct 118 ms 29268 KB Output is correct
38 Correct 156 ms 34072 KB Output is correct
39 Correct 162 ms 37724 KB Output is correct
40 Correct 234 ms 37700 KB Output is correct
41 Correct 229 ms 37692 KB Output is correct
42 Correct 171 ms 37712 KB Output is correct
43 Correct 149 ms 37716 KB Output is correct
44 Correct 153 ms 37720 KB Output is correct
45 Correct 162 ms 37968 KB Output is correct
46 Correct 155 ms 37912 KB Output is correct
47 Correct 153 ms 37716 KB Output is correct
48 Correct 175 ms 37820 KB Output is correct
49 Correct 173 ms 37832 KB Output is correct
50 Correct 152 ms 37652 KB Output is correct
51 Correct 159 ms 37712 KB Output is correct
52 Correct 198 ms 37660 KB Output is correct
53 Correct 205 ms 37712 KB Output is correct
54 Correct 195 ms 37708 KB Output is correct
55 Correct 565 ms 93040 KB Output is correct
56 Correct 167 ms 38788 KB Output is correct
57 Correct 363 ms 74872 KB Output is correct
58 Correct 460 ms 85328 KB Output is correct
59 Correct 458 ms 93012 KB Output is correct
60 Correct 575 ms 93200 KB Output is correct
61 Correct 607 ms 93316 KB Output is correct
62 Correct 421 ms 92992 KB Output is correct
63 Correct 448 ms 93008 KB Output is correct
64 Correct 411 ms 93300 KB Output is correct
65 Correct 445 ms 93660 KB Output is correct
66 Correct 458 ms 93684 KB Output is correct
67 Correct 456 ms 93476 KB Output is correct
68 Correct 464 ms 93284 KB Output is correct
69 Correct 504 ms 93576 KB Output is correct
70 Correct 480 ms 93328 KB Output is correct
71 Correct 471 ms 93300 KB Output is correct
72 Correct 574 ms 93076 KB Output is correct
73 Correct 600 ms 93448 KB Output is correct
74 Correct 613 ms 93008 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 856 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 1460 KB Output is correct
5 Correct 3 ms 1372 KB Output is correct
6 Correct 3 ms 1372 KB Output is correct
7 Correct 3 ms 1368 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 948 KB Output is correct
15 Correct 1 ms 1112 KB Output is correct
16 Correct 2 ms 1372 KB Output is correct
17 Correct 3 ms 1368 KB Output is correct
18 Correct 4 ms 1372 KB Output is correct
19 Correct 211 ms 37492 KB Output is correct
20 Correct 116 ms 29264 KB Output is correct
21 Correct 165 ms 37716 KB Output is correct
22 Correct 206 ms 37600 KB Output is correct
23 Correct 223 ms 37712 KB Output is correct
24 Correct 177 ms 37852 KB Output is correct
25 Correct 155 ms 37968 KB Output is correct
26 Correct 200 ms 37712 KB Output is correct
27 Correct 215 ms 37716 KB Output is correct
28 Correct 196 ms 37464 KB Output is correct
29 Correct 555 ms 93184 KB Output is correct
30 Correct 166 ms 38740 KB Output is correct
31 Correct 464 ms 93016 KB Output is correct
32 Correct 557 ms 93012 KB Output is correct
33 Correct 607 ms 93188 KB Output is correct
34 Correct 447 ms 94036 KB Output is correct
35 Correct 446 ms 93832 KB Output is correct
36 Correct 593 ms 93008 KB Output is correct
37 Correct 589 ms 93540 KB Output is correct
38 Correct 644 ms 93192 KB Output is correct
39 Execution timed out 2065 ms 705796 KB Time limit exceeded
40 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 856 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 1460 KB Output is correct
5 Correct 3 ms 1372 KB Output is correct
6 Correct 3 ms 1372 KB Output is correct
7 Correct 3 ms 1368 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 948 KB Output is correct
15 Correct 1 ms 1112 KB Output is correct
16 Correct 2 ms 1372 KB Output is correct
17 Correct 3 ms 1368 KB Output is correct
18 Correct 4 ms 1372 KB Output is correct
19 Correct 211 ms 37492 KB Output is correct
20 Correct 116 ms 29264 KB Output is correct
21 Correct 165 ms 37716 KB Output is correct
22 Correct 206 ms 37600 KB Output is correct
23 Correct 223 ms 37712 KB Output is correct
24 Correct 177 ms 37852 KB Output is correct
25 Correct 155 ms 37968 KB Output is correct
26 Correct 200 ms 37712 KB Output is correct
27 Correct 215 ms 37716 KB Output is correct
28 Correct 196 ms 37464 KB Output is correct
29 Correct 555 ms 93184 KB Output is correct
30 Correct 166 ms 38740 KB Output is correct
31 Correct 464 ms 93016 KB Output is correct
32 Correct 557 ms 93012 KB Output is correct
33 Correct 607 ms 93188 KB Output is correct
34 Correct 447 ms 94036 KB Output is correct
35 Correct 446 ms 93832 KB Output is correct
36 Correct 593 ms 93008 KB Output is correct
37 Correct 589 ms 93540 KB Output is correct
38 Correct 644 ms 93192 KB Output is correct
39 Execution timed out 2065 ms 705796 KB Time limit exceeded
40 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 856 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 1460 KB Output is correct
5 Correct 3 ms 1372 KB Output is correct
6 Correct 3 ms 1372 KB Output is correct
7 Correct 3 ms 1368 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 948 KB Output is correct
15 Correct 1 ms 1112 KB Output is correct
16 Correct 2 ms 1372 KB Output is correct
17 Correct 3 ms 1368 KB Output is correct
18 Correct 4 ms 1372 KB Output is correct
19 Correct 211 ms 37492 KB Output is correct
20 Correct 116 ms 29264 KB Output is correct
21 Correct 165 ms 37716 KB Output is correct
22 Correct 206 ms 37600 KB Output is correct
23 Correct 223 ms 37712 KB Output is correct
24 Correct 177 ms 37852 KB Output is correct
25 Correct 155 ms 37968 KB Output is correct
26 Correct 200 ms 37712 KB Output is correct
27 Correct 215 ms 37716 KB Output is correct
28 Correct 196 ms 37464 KB Output is correct
29 Correct 555 ms 93184 KB Output is correct
30 Correct 166 ms 38740 KB Output is correct
31 Correct 464 ms 93016 KB Output is correct
32 Correct 557 ms 93012 KB Output is correct
33 Correct 607 ms 93188 KB Output is correct
34 Correct 447 ms 94036 KB Output is correct
35 Correct 446 ms 93832 KB Output is correct
36 Correct 593 ms 93008 KB Output is correct
37 Correct 589 ms 93540 KB Output is correct
38 Correct 644 ms 93192 KB Output is correct
39 Execution timed out 2065 ms 705796 KB Time limit exceeded
40 Halted 0 ms 0 KB -