답안 #925864

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
925864 2024-02-12T10:14:18 Z Akshat369 Maze (JOI23_ho_t3) C++17
8 / 100
234 ms 154504 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define INF LLONG_MAX
#define endl '\n'
const int mod = 1000 * 1000 * 1000 + 7;
const int N = 100005;
#define f first
#define s second
#define rep(i, a, b) for(int i = (a); i < (b); i++)
#define rrep(i, a, b) for(int i = (a); i > (b); i--)
#define vi vector<int>
#define pii pair<int, int>

mt19937_64 RNG(chrono::steady_clock::now().time_since_epoch().count());

int dx[4] = {1,0,-1,0};
int dy[4] = {0,1,0,-1};

struct edge {
    int xx , yy , val;
    bool operator < (const edge& other) const {
        return val > other.val; // Compare based on distance
    }
};

void Solve() {
    int r , c , n; cin >> r >> c >> n;
    int sr , sc; cin >> sr >> sc;
    int gr, gc; cin >> gr >> gc;
    vector<vector<int>> vis(r + 3, vector<int>(c + 3));
    vector<vector<int>> mat(r + 3, vector<int>(c + 3, -1));
    vector<vector<int>> dis(r + 3, vector<int>(c + 3, INF));

    for (int i = 1; i <= r; ++i) {
        string s; cin >> s;
        for (int j = 1; j <= c; ++j) {
            if (s[j-1]=='.') mat[i][j] = 0;
            else mat[i][j] = 1;
        }
    }

    priority_queue<edge, vector<edge>> pq;
    pq.push({sr, sc, mat[sr][sc]}); // Start node with distance 0
    dis[sr][sc] = mat[sr][sc]; // Distance to start node is 0

    while (!pq.empty()) {
        auto node = pq.top();
        pq.pop();
        if (vis[node.xx][node.yy]) continue;
        vis[node.xx][node.yy] = true;

        for (int i = 0; i < 4; ++i) {
            int nx = node.xx + dx[i];
            int ny = node.yy + dy[i];
            if (nx >= 1 && nx <= r && ny >= 1 && ny <= c && mat[nx][ny] != -1) {
                int new_dist = dis[node.xx][node.yy] + mat[nx][ny];
                if (new_dist < dis[nx][ny]) {
                    dis[nx][ny] = new_dist;
                    pq.push({nx, ny, new_dist});
                }
            }
        }
    }

    cout << dis[gr][gc] << endl;
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int t = 1;
    // cin >> t;
    for (int i = 1; i <= t; i++) {
        Solve();
    }
    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 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 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 460 KB Output is correct
11 Correct 0 ms 464 KB Output is correct
12 Correct 1 ms 600 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 456 KB Output is correct
17 Correct 0 ms 460 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 5 ms 1884 KB Output is correct
20 Correct 3 ms 5104 KB Output is correct
21 Correct 7 ms 2904 KB Output is correct
22 Correct 6 ms 2008 KB Output is correct
23 Correct 5 ms 1884 KB Output is correct
24 Correct 5 ms 6532 KB Output is correct
25 Correct 4 ms 6532 KB Output is correct
26 Correct 7 ms 2252 KB Output is correct
27 Correct 7 ms 2140 KB Output is correct
28 Correct 6 ms 2012 KB Output is correct
29 Correct 13 ms 4196 KB Output is correct
30 Correct 5 ms 4204 KB Output is correct
31 Correct 17 ms 5844 KB Output is correct
32 Correct 15 ms 4188 KB Output is correct
33 Correct 13 ms 4188 KB Output is correct
34 Correct 12 ms 15816 KB Output is correct
35 Correct 10 ms 15816 KB Output is correct
36 Correct 18 ms 4636 KB Output is correct
37 Correct 16 ms 4440 KB Output is correct
38 Correct 14 ms 4388 KB Output is correct
39 Correct 165 ms 37520 KB Output is correct
40 Correct 14 ms 5212 KB Output is correct
41 Correct 18 ms 19664 KB Output is correct
42 Correct 19 ms 5724 KB Output is correct
43 Correct 15 ms 15784 KB Output is correct
44 Correct 64 ms 28308 KB Output is correct
45 Correct 52 ms 32644 KB Output is correct
46 Correct 234 ms 62300 KB Output is correct
47 Correct 175 ms 37572 KB Output is correct
48 Correct 180 ms 37716 KB Output is correct
49 Correct 107 ms 154500 KB Output is correct
50 Correct 77 ms 154504 KB Output is correct
51 Correct 204 ms 39084 KB Output is correct
52 Correct 189 ms 37920 KB Output is correct
53 Correct 177 ms 37972 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 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 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 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 460 KB Output is correct
11 Correct 0 ms 464 KB Output is correct
12 Correct 1 ms 600 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 456 KB Output is correct
17 Correct 0 ms 460 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 5 ms 1884 KB Output is correct
20 Correct 3 ms 5104 KB Output is correct
21 Correct 7 ms 2904 KB Output is correct
22 Correct 6 ms 2008 KB Output is correct
23 Correct 5 ms 1884 KB Output is correct
24 Correct 5 ms 6532 KB Output is correct
25 Correct 4 ms 6532 KB Output is correct
26 Correct 7 ms 2252 KB Output is correct
27 Correct 7 ms 2140 KB Output is correct
28 Correct 6 ms 2012 KB Output is correct
29 Correct 13 ms 4196 KB Output is correct
30 Correct 5 ms 4204 KB Output is correct
31 Correct 17 ms 5844 KB Output is correct
32 Correct 15 ms 4188 KB Output is correct
33 Correct 13 ms 4188 KB Output is correct
34 Correct 12 ms 15816 KB Output is correct
35 Correct 10 ms 15816 KB Output is correct
36 Correct 18 ms 4636 KB Output is correct
37 Correct 16 ms 4440 KB Output is correct
38 Correct 14 ms 4388 KB Output is correct
39 Correct 165 ms 37520 KB Output is correct
40 Correct 14 ms 5212 KB Output is correct
41 Correct 18 ms 19664 KB Output is correct
42 Correct 19 ms 5724 KB Output is correct
43 Correct 15 ms 15784 KB Output is correct
44 Correct 64 ms 28308 KB Output is correct
45 Correct 52 ms 32644 KB Output is correct
46 Correct 234 ms 62300 KB Output is correct
47 Correct 175 ms 37572 KB Output is correct
48 Correct 180 ms 37716 KB Output is correct
49 Correct 107 ms 154500 KB Output is correct
50 Correct 77 ms 154504 KB Output is correct
51 Correct 204 ms 39084 KB Output is correct
52 Correct 189 ms 37920 KB Output is correct
53 Correct 177 ms 37972 KB Output is correct
54 Incorrect 0 ms 348 KB Output isn't correct
55 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 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 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 460 KB Output is correct
11 Correct 0 ms 464 KB Output is correct
12 Correct 1 ms 600 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 456 KB Output is correct
17 Correct 0 ms 460 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 5 ms 1884 KB Output is correct
20 Correct 3 ms 5104 KB Output is correct
21 Correct 7 ms 2904 KB Output is correct
22 Correct 6 ms 2008 KB Output is correct
23 Correct 5 ms 1884 KB Output is correct
24 Correct 5 ms 6532 KB Output is correct
25 Correct 4 ms 6532 KB Output is correct
26 Correct 7 ms 2252 KB Output is correct
27 Correct 7 ms 2140 KB Output is correct
28 Correct 6 ms 2012 KB Output is correct
29 Correct 13 ms 4196 KB Output is correct
30 Correct 5 ms 4204 KB Output is correct
31 Correct 17 ms 5844 KB Output is correct
32 Correct 15 ms 4188 KB Output is correct
33 Correct 13 ms 4188 KB Output is correct
34 Correct 12 ms 15816 KB Output is correct
35 Correct 10 ms 15816 KB Output is correct
36 Correct 18 ms 4636 KB Output is correct
37 Correct 16 ms 4440 KB Output is correct
38 Correct 14 ms 4388 KB Output is correct
39 Correct 165 ms 37520 KB Output is correct
40 Correct 14 ms 5212 KB Output is correct
41 Correct 18 ms 19664 KB Output is correct
42 Correct 19 ms 5724 KB Output is correct
43 Correct 15 ms 15784 KB Output is correct
44 Correct 64 ms 28308 KB Output is correct
45 Correct 52 ms 32644 KB Output is correct
46 Correct 234 ms 62300 KB Output is correct
47 Correct 175 ms 37572 KB Output is correct
48 Correct 180 ms 37716 KB Output is correct
49 Correct 107 ms 154500 KB Output is correct
50 Correct 77 ms 154504 KB Output is correct
51 Correct 204 ms 39084 KB Output is correct
52 Correct 189 ms 37920 KB Output is correct
53 Correct 177 ms 37972 KB Output is correct
54 Incorrect 0 ms 348 KB Output isn't correct
55 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 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 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 460 KB Output is correct
11 Correct 0 ms 464 KB Output is correct
12 Correct 1 ms 600 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 456 KB Output is correct
17 Correct 0 ms 460 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 5 ms 1884 KB Output is correct
20 Correct 3 ms 5104 KB Output is correct
21 Correct 7 ms 2904 KB Output is correct
22 Correct 6 ms 2008 KB Output is correct
23 Correct 5 ms 1884 KB Output is correct
24 Correct 5 ms 6532 KB Output is correct
25 Correct 4 ms 6532 KB Output is correct
26 Correct 7 ms 2252 KB Output is correct
27 Correct 7 ms 2140 KB Output is correct
28 Correct 6 ms 2012 KB Output is correct
29 Correct 13 ms 4196 KB Output is correct
30 Correct 5 ms 4204 KB Output is correct
31 Correct 17 ms 5844 KB Output is correct
32 Correct 15 ms 4188 KB Output is correct
33 Correct 13 ms 4188 KB Output is correct
34 Correct 12 ms 15816 KB Output is correct
35 Correct 10 ms 15816 KB Output is correct
36 Correct 18 ms 4636 KB Output is correct
37 Correct 16 ms 4440 KB Output is correct
38 Correct 14 ms 4388 KB Output is correct
39 Correct 165 ms 37520 KB Output is correct
40 Correct 14 ms 5212 KB Output is correct
41 Correct 18 ms 19664 KB Output is correct
42 Correct 19 ms 5724 KB Output is correct
43 Correct 15 ms 15784 KB Output is correct
44 Correct 64 ms 28308 KB Output is correct
45 Correct 52 ms 32644 KB Output is correct
46 Correct 234 ms 62300 KB Output is correct
47 Correct 175 ms 37572 KB Output is correct
48 Correct 180 ms 37716 KB Output is correct
49 Correct 107 ms 154500 KB Output is correct
50 Correct 77 ms 154504 KB Output is correct
51 Correct 204 ms 39084 KB Output is correct
52 Correct 189 ms 37920 KB Output is correct
53 Correct 177 ms 37972 KB Output is correct
54 Incorrect 0 ms 348 KB Output isn't correct
55 Halted 0 ms 0 KB -