답안 #931574

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
931574 2024-02-22T05:48:59 Z Pring Maze (JOI23_ho_t3) C++17
0 / 100
1 ms 600 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 = 1500005, INF = 3.9e18;
int r, c, n;
pii sr, to;
pii dd[4] = {mp(1LL, 0LL), mp(-1LL, 0LL), mp(0LL, 1LL), mp(0LL, -1LL)};
vector<string> s;
vector<vector<pii>> edge;
vector<int> dis;
priority_queue<pii, vector<pii>, greater<pii>> pq;

inline int f(pii p) {
    return p.fs * c + p.sc;
}

inline pii f(int x) {
    return mp(x / c, x % c);
}

bool OUT(pii p) {
    if (p.fs < 0 || r <= p.fs) return true;
    if (p.fs < 0 || c <= p.sc) return true;
    return false;
}

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

int get_val(pii p) {
    return (s[p.fs][p.sc] == '#');
}

void BUILD_EDGE() {
    edge.resize(r * c);
    FOR(i, 0, r * c) {
        pii now = f(i);
        // int val = get_val(now);
        FOR(d, 0, 4) {
            if (OUT(now + dd[d])) continue;
            edge[i].push_back(mp(get_val(now) + get_val(now + dd[d]), f(now + dd[d])));
        }
    }
}

void DIJKSTRA(int sr) {
    dis = vector<int>(r * c, INF);
    pq.push(mp(0LL, sr));
    while (pq.size()) {
        int len = pq.top().fs, id = pq.top().sc;
        pq.pop();
        if (dis[id] != INF) continue;
        dis[id] = len;
        for (auto &i : edge[id]) {
            if (dis[i.sc] != INF) continue;
            pq.push(mp(i.fs + len, i.sc));
        }
    }
}
 
void miku() {
    cin >> r >> c >> n >> sr.fs >> sr.sc >> to.fs >> to.sc;
    sr.fs--;
    sr.sc--;
    to.fs--;
    to.sc--;
    s.resize(r);
    for (auto &i : s) cin >> i;
    BUILD_EDGE();
    // BUILD_FRAME();
    DIJKSTRA(f(sr));
    // assert(dis[f(to)] < r * c);
    cout << dis[f(to)] / 2 << '\n';
}
 
int32_t main() {
    cin.tie(0) -> sync_with_stdio(false);
    cin.exceptions(iostream::failbit);
    miku();
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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 1 ms 344 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 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 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Incorrect 1 ms 348 KB Output isn't correct
15 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 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 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 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 1 ms 348 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 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 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Incorrect 1 ms 348 KB Output isn't correct
15 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 1 ms 348 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 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 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Incorrect 1 ms 348 KB Output isn't correct
15 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 1 ms 348 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 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 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Incorrect 1 ms 348 KB Output isn't correct
15 Halted 0 ms 0 KB -