답안 #932886

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
932886 2024-02-24T10:48:32 Z Pring Maze (JOI23_ho_t3) C++17
8 / 100
257 ms 66228 KB
#include <bits/stdc++.h>
using namespace std;

#ifdef MIKU
#define debug(x...) cout << "[" << #x << "] : ", dout(x)
void dout() { cout << endl; }
template <typename T, typename ...U>
void dout(T t, U ...u) { cout << t << (sizeof...(u) ? ", " : ""); dout(u...); }
#else
#define debug(...) 39
#endif

// #define int long long
#define fs first
#define sc second
#define mp make_pair
#define FOR(i, j, k) for (int i = j, Z = k; i < Z; i++)
typedef pair<int, int> pii;

const int MXN = 6000005, LAYER = 8;
const pii D[4] = {mp(1, 0), mp(-1, 0), mp(0, 1), mp(0, -1)};
int R, C, N;
pii sr, to;
vector<string> s;
int K;
int dis[MXN * LAYER];
vector<int> v0, v1;
int cnt;

inline int cvt(pii p) {
    return p.fs * C + p.sc;
}

inline pii cvt(int x) {
    return mp(x / C, x % C);
}

inline pii operator+(pii a, pii b) {
    return mp(a.fs + b.fs, a.sc + b.sc);
}

inline bool OUT(pii p) {
    if (!(0 <= p.fs && p.fs < R)) return true;
    if (!(0 <= p.sc && p.sc < C)) return true;
    return false;
}

namespace EDGE {
    inline int cvt3(int l, int x, int y) {
        return l * R * C + x * C + y;
    }

    inline void PUSH_EDGE(int sr, int to, int val) {
        (val ? v1 : v0).push_back(to);
    }

    void E0(pii p) {
        FOR(d, 0, 4) {
            pii nxt = p + D[d];
            if (OUT(nxt)) continue;
            if (s[p.fs][p.sc] == '.' && s[nxt.fs][nxt.sc] == '.') PUSH_EDGE(cvt3(0, p.fs, p.sc), cvt3(0, nxt.fs, nxt.sc), 0);
            PUSH_EDGE(cvt3(0, p.fs, p.sc), cvt3(1, nxt.fs, nxt.sc), 1);
        }
    }

    void E1(pii p) {
        int l = max(0, p.fs - (N - 1)), r = min(R, p.fs + N);
        int y = p.sc, sr = cvt3(1, p.fs, p.sc);
        if (r - l == K) {
            PUSH_EDGE(sr, cvt3(2, l, y), 0);
            PUSH_EDGE(sr, cvt3(3, r - 1, y), 0);
            return;
        }
        if (r == R) {
            PUSH_EDGE(sr, cvt3(2, l, y), 0);
            int m = (l ? (l - 1) / K * K + K : 0);
            if (m < R) PUSH_EDGE(sr, cvt3(2, m, y), 0);
            return;
        }
        PUSH_EDGE(sr, cvt3(3, r - 1, y), 0);
    }

    void E2(pii p) {
        PUSH_EDGE(cvt3(2, p.fs, p.sc), cvt3(4, p.fs, p.sc), 0);
        if (p.fs == R - 1 || (p.fs + 1) % K == 0) return;
        PUSH_EDGE(cvt3(2, p.fs, p.sc), cvt3(2, p.fs + 1, p.sc), 0);
    }

    void E3(pii p) {
        PUSH_EDGE(cvt3(3, p.fs, p.sc), cvt3(4, p.fs, p.sc), 0);
        if (p.fs % K == 0) return;
        PUSH_EDGE(cvt3(3, p.fs, p.sc), cvt3(3, p.fs - 1, p.sc), 0);
    }

    void E4(pii p) {
        int l = max(0, p.sc - (N - 1)), r = min(C, p.sc + N);
        int x = p.fs, sr = cvt3(4, p.fs, p.sc);
        if (r - l == K) {
            PUSH_EDGE(sr, cvt3(5, x, l), 0);
            PUSH_EDGE(sr, cvt3(6, x, r - 1), 0);
            return;
        }
        if (r == C) {
            PUSH_EDGE(sr, cvt3(5, x, l), 0);
            int m = (l ? (l - 1) / K * K + K : 0);
            if (m < C) PUSH_EDGE(sr, cvt3(5, x, m), 0);
            return;
        }
        PUSH_EDGE(sr, cvt3(6, x, r - 1), 0);
    }

    void E5(pii p) {
        PUSH_EDGE(cvt3(5, p.fs, p.sc), cvt3(7, p.fs, p.sc), 0);
        if (p.sc + 1 == C || (p.sc - 1) % K == 0) return;
        PUSH_EDGE(cvt3(5, p.fs, p.sc), cvt3(5, p.fs, p.sc + 1), 0);
    }

    void E6(pii p) {
        PUSH_EDGE(cvt3(6, p.fs, p.sc), cvt3(7, p.fs, p.sc), 0);
        if (p.sc % K == 0) return;
        PUSH_EDGE(cvt3(6, p.fs, p.sc), cvt3(6, p.fs, p.sc - 1), 0);
    }

    void E7(pii p) {
        PUSH_EDGE(cvt3(7, p.fs, p.sc), cvt3(0, p.fs, p.sc), 0);
        FOR(d, 0, 4) {
            pii nxt = p + D[d];
            if (OUT(nxt) || s[nxt.fs][nxt.sc] == '#') continue;
            PUSH_EDGE(cvt3(7, p.fs, p.sc), cvt3(0, nxt.fs, nxt.sc), 0);
        }
    }

    void BUILD(int id) {
        int l = id / (C * R);
        pii p = cvt(id % (C * R));
        // debug(l, p.fs, p.sc);
        if (l == 0) E0(p);
        else if (l == 1) E1(p);
        else if (l == 2) E2(p);
        else if (l == 3) E3(p);
        else if (l == 4) E4(p);
        else if (l == 5) E5(p);
        else if (l == 6) E6(p);
        else E7(p);
    }
}

namespace BFS {
    void GO(int sr, int to) {
        fill(dis, dis + R * C * LAYER, -1);
        v0.push_back(sr);
        while (v0.size()) {
            for (int i = 0; i < v0.size(); i++) {
                int id = v0[i];
                if (dis[id] != -1) continue;
                dis[id] = cnt;
                if (id == to) return;
                EDGE::BUILD(id);
            }
            swap(v0, v1);
            v1.clear();
            cnt++;
        }
    }
}

void miku() {
    cin >> R >> C >> N >> sr.fs >> sr.sc >> to.fs >> to.sc;
    sr.fs--, sr.sc--, to.fs--, to.sc--;
    K = N * 2 - 1;
    s.resize(R);
    FOR(i, 0, R) cin >> s[i];
    // EDGE::BUILD();
    BFS::GO(cvt(sr), cvt(to));
    cout << dis[cvt(to)] << '\n';
}

int32_t main() {
    cin.tie(0) -> sync_with_stdio(false);
    cin.exceptions(iostream::failbit);
    miku();
    return 0;
}

Compilation message

Main.cpp: In function 'void BFS::GO(int, int)':
Main.cpp:153:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  153 |             for (int i = 0; i < v0.size(); i++) {
      |                             ~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 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 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 7 ms 2652 KB Output is correct
20 Correct 4 ms 2652 KB Output is correct
21 Correct 3 ms 4280 KB Output is correct
22 Correct 10 ms 3164 KB Output is correct
23 Correct 8 ms 2652 KB Output is correct
24 Correct 6 ms 2996 KB Output is correct
25 Correct 6 ms 2652 KB Output is correct
26 Correct 1 ms 2908 KB Output is correct
27 Correct 1 ms 2908 KB Output is correct
28 Correct 4 ms 3076 KB Output is correct
29 Correct 21 ms 7004 KB Output is correct
30 Correct 7 ms 2652 KB Output is correct
31 Correct 9 ms 15036 KB Output is correct
32 Correct 27 ms 7616 KB Output is correct
33 Correct 18 ms 7232 KB Output is correct
34 Correct 17 ms 7144 KB Output is correct
35 Correct 15 ms 7144 KB Output is correct
36 Correct 16 ms 9188 KB Output is correct
37 Correct 22 ms 7952 KB Output is correct
38 Correct 3 ms 7516 KB Output is correct
39 Correct 257 ms 49760 KB Output is correct
40 Correct 9 ms 7256 KB Output is correct
41 Correct 11 ms 7144 KB Output is correct
42 Correct 33 ms 9304 KB Output is correct
43 Correct 25 ms 9308 KB Output is correct
44 Correct 46 ms 26968 KB Output is correct
45 Correct 54 ms 29168 KB Output is correct
46 Correct 26 ms 66228 KB Output is correct
47 Correct 257 ms 52040 KB Output is correct
48 Correct 192 ms 51084 KB Output is correct
49 Correct 110 ms 50944 KB Output is correct
50 Correct 96 ms 50684 KB Output is correct
51 Correct 205 ms 59772 KB Output is correct
52 Correct 140 ms 54868 KB Output is correct
53 Correct 187 ms 52244 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Incorrect 0 ms 348 KB Output isn't correct
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Incorrect 1 ms 348 KB Output isn't correct
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Incorrect 0 ms 348 KB Output isn't correct
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Incorrect 0 ms 348 KB Output isn't correct
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 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 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 7 ms 2652 KB Output is correct
20 Correct 4 ms 2652 KB Output is correct
21 Correct 3 ms 4280 KB Output is correct
22 Correct 10 ms 3164 KB Output is correct
23 Correct 8 ms 2652 KB Output is correct
24 Correct 6 ms 2996 KB Output is correct
25 Correct 6 ms 2652 KB Output is correct
26 Correct 1 ms 2908 KB Output is correct
27 Correct 1 ms 2908 KB Output is correct
28 Correct 4 ms 3076 KB Output is correct
29 Correct 21 ms 7004 KB Output is correct
30 Correct 7 ms 2652 KB Output is correct
31 Correct 9 ms 15036 KB Output is correct
32 Correct 27 ms 7616 KB Output is correct
33 Correct 18 ms 7232 KB Output is correct
34 Correct 17 ms 7144 KB Output is correct
35 Correct 15 ms 7144 KB Output is correct
36 Correct 16 ms 9188 KB Output is correct
37 Correct 22 ms 7952 KB Output is correct
38 Correct 3 ms 7516 KB Output is correct
39 Correct 257 ms 49760 KB Output is correct
40 Correct 9 ms 7256 KB Output is correct
41 Correct 11 ms 7144 KB Output is correct
42 Correct 33 ms 9304 KB Output is correct
43 Correct 25 ms 9308 KB Output is correct
44 Correct 46 ms 26968 KB Output is correct
45 Correct 54 ms 29168 KB Output is correct
46 Correct 26 ms 66228 KB Output is correct
47 Correct 257 ms 52040 KB Output is correct
48 Correct 192 ms 51084 KB Output is correct
49 Correct 110 ms 50944 KB Output is correct
50 Correct 96 ms 50684 KB Output is correct
51 Correct 205 ms 59772 KB Output is correct
52 Correct 140 ms 54868 KB Output is correct
53 Correct 187 ms 52244 KB Output is correct
54 Correct 0 ms 344 KB Output is correct
55 Correct 0 ms 344 KB Output is correct
56 Correct 0 ms 348 KB Output is correct
57 Correct 0 ms 348 KB Output is correct
58 Correct 0 ms 348 KB Output is correct
59 Correct 0 ms 348 KB Output is correct
60 Correct 0 ms 348 KB Output is correct
61 Correct 0 ms 348 KB Output is correct
62 Correct 0 ms 348 KB Output is correct
63 Correct 1 ms 348 KB Output is correct
64 Correct 1 ms 348 KB Output is correct
65 Correct 1 ms 348 KB Output is correct
66 Incorrect 0 ms 348 KB Output isn't correct
67 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 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 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 7 ms 2652 KB Output is correct
20 Correct 4 ms 2652 KB Output is correct
21 Correct 3 ms 4280 KB Output is correct
22 Correct 10 ms 3164 KB Output is correct
23 Correct 8 ms 2652 KB Output is correct
24 Correct 6 ms 2996 KB Output is correct
25 Correct 6 ms 2652 KB Output is correct
26 Correct 1 ms 2908 KB Output is correct
27 Correct 1 ms 2908 KB Output is correct
28 Correct 4 ms 3076 KB Output is correct
29 Correct 21 ms 7004 KB Output is correct
30 Correct 7 ms 2652 KB Output is correct
31 Correct 9 ms 15036 KB Output is correct
32 Correct 27 ms 7616 KB Output is correct
33 Correct 18 ms 7232 KB Output is correct
34 Correct 17 ms 7144 KB Output is correct
35 Correct 15 ms 7144 KB Output is correct
36 Correct 16 ms 9188 KB Output is correct
37 Correct 22 ms 7952 KB Output is correct
38 Correct 3 ms 7516 KB Output is correct
39 Correct 257 ms 49760 KB Output is correct
40 Correct 9 ms 7256 KB Output is correct
41 Correct 11 ms 7144 KB Output is correct
42 Correct 33 ms 9304 KB Output is correct
43 Correct 25 ms 9308 KB Output is correct
44 Correct 46 ms 26968 KB Output is correct
45 Correct 54 ms 29168 KB Output is correct
46 Correct 26 ms 66228 KB Output is correct
47 Correct 257 ms 52040 KB Output is correct
48 Correct 192 ms 51084 KB Output is correct
49 Correct 110 ms 50944 KB Output is correct
50 Correct 96 ms 50684 KB Output is correct
51 Correct 205 ms 59772 KB Output is correct
52 Correct 140 ms 54868 KB Output is correct
53 Correct 187 ms 52244 KB Output is correct
54 Correct 0 ms 344 KB Output is correct
55 Correct 0 ms 344 KB Output is correct
56 Correct 0 ms 348 KB Output is correct
57 Correct 0 ms 348 KB Output is correct
58 Correct 0 ms 348 KB Output is correct
59 Correct 0 ms 348 KB Output is correct
60 Correct 0 ms 348 KB Output is correct
61 Correct 0 ms 348 KB Output is correct
62 Correct 0 ms 348 KB Output is correct
63 Correct 1 ms 348 KB Output is correct
64 Correct 1 ms 348 KB Output is correct
65 Correct 1 ms 348 KB Output is correct
66 Incorrect 0 ms 348 KB Output isn't correct
67 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 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 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 7 ms 2652 KB Output is correct
20 Correct 4 ms 2652 KB Output is correct
21 Correct 3 ms 4280 KB Output is correct
22 Correct 10 ms 3164 KB Output is correct
23 Correct 8 ms 2652 KB Output is correct
24 Correct 6 ms 2996 KB Output is correct
25 Correct 6 ms 2652 KB Output is correct
26 Correct 1 ms 2908 KB Output is correct
27 Correct 1 ms 2908 KB Output is correct
28 Correct 4 ms 3076 KB Output is correct
29 Correct 21 ms 7004 KB Output is correct
30 Correct 7 ms 2652 KB Output is correct
31 Correct 9 ms 15036 KB Output is correct
32 Correct 27 ms 7616 KB Output is correct
33 Correct 18 ms 7232 KB Output is correct
34 Correct 17 ms 7144 KB Output is correct
35 Correct 15 ms 7144 KB Output is correct
36 Correct 16 ms 9188 KB Output is correct
37 Correct 22 ms 7952 KB Output is correct
38 Correct 3 ms 7516 KB Output is correct
39 Correct 257 ms 49760 KB Output is correct
40 Correct 9 ms 7256 KB Output is correct
41 Correct 11 ms 7144 KB Output is correct
42 Correct 33 ms 9304 KB Output is correct
43 Correct 25 ms 9308 KB Output is correct
44 Correct 46 ms 26968 KB Output is correct
45 Correct 54 ms 29168 KB Output is correct
46 Correct 26 ms 66228 KB Output is correct
47 Correct 257 ms 52040 KB Output is correct
48 Correct 192 ms 51084 KB Output is correct
49 Correct 110 ms 50944 KB Output is correct
50 Correct 96 ms 50684 KB Output is correct
51 Correct 205 ms 59772 KB Output is correct
52 Correct 140 ms 54868 KB Output is correct
53 Correct 187 ms 52244 KB Output is correct
54 Correct 0 ms 344 KB Output is correct
55 Correct 0 ms 344 KB Output is correct
56 Correct 0 ms 348 KB Output is correct
57 Correct 0 ms 348 KB Output is correct
58 Correct 0 ms 348 KB Output is correct
59 Correct 0 ms 348 KB Output is correct
60 Correct 0 ms 348 KB Output is correct
61 Correct 0 ms 348 KB Output is correct
62 Correct 0 ms 348 KB Output is correct
63 Correct 1 ms 348 KB Output is correct
64 Correct 1 ms 348 KB Output is correct
65 Correct 1 ms 348 KB Output is correct
66 Incorrect 0 ms 348 KB Output isn't correct
67 Halted 0 ms 0 KB -