답안 #1087831

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1087831 2024-09-13T09:53:42 Z jonghak9028 날다람쥐 (JOI14_ho_t4) C++17
50 / 100
363 ms 34900 KB
/* ************************************************************************** */
/*                                                                            */
/*                                                      :::    :::    :::     */
/*   Problem Number: 10048                             :+:    :+:      :+:    */
/*                                                    +:+    +:+        +:+   */
/*   By: js9028 <boj.kr/u/js9028>                    +#+    +#+          +#+  */
/*                                                  +#+      +#+        +#+   */
/*   https://boj.kr/10048                          #+#        #+#      #+#    */
/*   Solved: 2024/09/13 17:30:05 by js9028        ###          ###   ##.kr    */
/*                                                                            */
/* ************************************************************************** */
#include<queue>
#include<vector>
#include<iostream>
#include<array>

using namespace std;
#define fastio (ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL))
typedef long long ll;
typedef long double lld;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
const int MAXSIZE = 2000000;
const long long INF = 1e18 + 5;
const double EPSILON = 1e-14;
const ll DIV = 2000003;
const long double pi = 3.14159265358979323846264338327950288419716939937510L;

int n, m;
ll x;
ll hei[100055];
vector<pair<int, ll>> adj[100055];

ll dist[100055];

ll bfs()
{
    ll ans = INF;
    priority_queue<array<ll, 3>, vector<array<ll, 3>>, greater<array<ll, 3>>> pq;
    pq.push({ 0ll, 1ll, x });
    fill(dist, dist + n + 3, INF);
    dist[1] = 0;
    while (!pq.empty())
    {
        auto [d, cur, h] = pq.top();
        pq.pop();
        if (cur == n)
        {
            ans = min(ans, d + (hei[n] - h));
        }
        for (auto& nxt : adj[cur])
        {
            ll nd = dist[cur] + nxt.second;
            ll nh = h - nxt.second;
            if (nh < 0)
            {
                nd += -nh;
                nh = 0;
            }
            if (nh > hei[nxt.first])
            {
                nd += nh - hei[nxt.first];
                nh = hei[nxt.first];
            }

            if (dist[nxt.first] <= nd || hei[cur] < nxt.second)
                continue;
            dist[nxt.first] = nd;
            pq.push({ nd, (ll)nxt.first, nh });
        }
    }
    return ans == INF ? -1 : ans;
}

int main()
{
    fastio;
    cin >> n >> m >> x;
    for (int i = 1; i <= n; i++)
        cin >> hei[i];
    for (int i = 0; i < m; i++)
    {
        int a, b, c;
        cin >> a >> b >> c;
        adj[a].push_back({ b, c });
        adj[b].push_back({ a, c });
    }
    cout << bfs();
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2904 KB Output is correct
2 Correct 2 ms 2908 KB Output is correct
3 Correct 2 ms 2928 KB Output is correct
4 Correct 1 ms 2908 KB Output is correct
5 Correct 2 ms 2908 KB Output is correct
6 Correct 1 ms 2652 KB Output is correct
7 Correct 1 ms 2652 KB Output is correct
8 Correct 2 ms 2908 KB Output is correct
9 Correct 2 ms 2908 KB Output is correct
10 Correct 2 ms 2908 KB Output is correct
11 Correct 1 ms 2652 KB Output is correct
12 Correct 2 ms 2908 KB Output is correct
13 Correct 2 ms 2908 KB Output is correct
14 Correct 1 ms 2652 KB Output is correct
15 Correct 2 ms 2908 KB Output is correct
16 Correct 2 ms 2904 KB Output is correct
17 Correct 1 ms 2820 KB Output is correct
18 Correct 2 ms 2652 KB Output is correct
19 Correct 2 ms 2652 KB Output is correct
20 Correct 1 ms 2908 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 127 ms 26788 KB Output is correct
2 Correct 99 ms 26080 KB Output is correct
3 Correct 64 ms 14536 KB Output is correct
4 Correct 107 ms 26316 KB Output is correct
5 Correct 84 ms 24524 KB Output is correct
6 Correct 6 ms 3928 KB Output is correct
7 Correct 105 ms 24912 KB Output is correct
8 Correct 111 ms 22796 KB Output is correct
9 Correct 105 ms 25044 KB Output is correct
10 Correct 66 ms 18768 KB Output is correct
11 Correct 12 ms 4952 KB Output is correct
12 Correct 67 ms 17980 KB Output is correct
13 Correct 35 ms 13136 KB Output is correct
14 Correct 97 ms 24660 KB Output is correct
15 Correct 4 ms 3416 KB Output is correct
16 Correct 86 ms 24328 KB Output is correct
17 Correct 11 ms 4700 KB Output is correct
18 Correct 11 ms 5132 KB Output is correct
19 Correct 39 ms 12116 KB Output is correct
20 Correct 12 ms 5464 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2904 KB Output is correct
2 Correct 2 ms 2908 KB Output is correct
3 Correct 2 ms 2928 KB Output is correct
4 Correct 1 ms 2908 KB Output is correct
5 Correct 2 ms 2908 KB Output is correct
6 Correct 1 ms 2652 KB Output is correct
7 Correct 1 ms 2652 KB Output is correct
8 Correct 2 ms 2908 KB Output is correct
9 Correct 2 ms 2908 KB Output is correct
10 Correct 2 ms 2908 KB Output is correct
11 Correct 1 ms 2652 KB Output is correct
12 Correct 2 ms 2908 KB Output is correct
13 Correct 2 ms 2908 KB Output is correct
14 Correct 1 ms 2652 KB Output is correct
15 Correct 2 ms 2908 KB Output is correct
16 Correct 2 ms 2904 KB Output is correct
17 Correct 1 ms 2820 KB Output is correct
18 Correct 2 ms 2652 KB Output is correct
19 Correct 2 ms 2652 KB Output is correct
20 Correct 1 ms 2908 KB Output is correct
21 Correct 127 ms 26788 KB Output is correct
22 Correct 99 ms 26080 KB Output is correct
23 Correct 64 ms 14536 KB Output is correct
24 Correct 107 ms 26316 KB Output is correct
25 Correct 84 ms 24524 KB Output is correct
26 Correct 6 ms 3928 KB Output is correct
27 Correct 105 ms 24912 KB Output is correct
28 Correct 111 ms 22796 KB Output is correct
29 Correct 105 ms 25044 KB Output is correct
30 Correct 66 ms 18768 KB Output is correct
31 Correct 12 ms 4952 KB Output is correct
32 Correct 67 ms 17980 KB Output is correct
33 Correct 35 ms 13136 KB Output is correct
34 Correct 97 ms 24660 KB Output is correct
35 Correct 4 ms 3416 KB Output is correct
36 Correct 86 ms 24328 KB Output is correct
37 Correct 11 ms 4700 KB Output is correct
38 Correct 11 ms 5132 KB Output is correct
39 Correct 39 ms 12116 KB Output is correct
40 Correct 12 ms 5464 KB Output is correct
41 Correct 80 ms 24052 KB Output is correct
42 Correct 17 ms 6744 KB Output is correct
43 Correct 76 ms 21368 KB Output is correct
44 Correct 49 ms 11596 KB Output is correct
45 Incorrect 363 ms 34900 KB Output isn't correct
46 Halted 0 ms 0 KB -