답안 #1099217

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1099217 2024-10-10T19:49:53 Z NoMercy Airplane (NOI23_airplane) C++17
100 / 100
298 ms 29272 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
 
const ll inf = 1e18;

int32_t main () {

    ios_base::sync_with_stdio(0); 
    cin.tie(0); 
    cout.tie(0); 

    int N, M;
    cin >> N >> M;
    vector<int> h(N), g[N];
    vector<array<ll, 2>> dist(N);
    for (int i = 0;i < N;i ++) {
        cin >> h[i];
    }
    for (int i = 0;i < M;i ++) {
        int u, v; 
        cin >> u >> v;
        -- u;
        -- v;
        g[u].push_back(v);
        g[v].push_back(u);
    }
 
    function<void(int, int)> dijikstra = [&](int si, int ti) -> void {
        for (int i = 0;i < N;i ++) {
            dist[i][ti] = inf;
        }
        dist[si][ti] = 0;
        multiset<array<ll, 2>> dj;
        dj.insert({dist[si][ti], si});
        while (dj.size() > 0) {
            auto [w, u] = *dj.begin();
            dj.erase(dj.begin());
            if (w != dist[u][ti]) continue;
            for (auto v : g[u]) if (dist[v][ti] > max(1LL * h[v], dist[u][ti] + 1)) {
                dist[v][ti] = max(1LL * h[v], dist[u][ti] + 1);
                dj.insert({dist[v][ti], v});
            }
        }
    };
    dijikstra(0, 0);
    dijikstra(N - 1, 1);

    ll ans = inf;
    for (int u = 0;u < N;u ++) {
        ans = min(ans, max(dist[u][0], dist[u][1]) * 2);
        for (auto v : g[u]) {
            ans = min(ans, max(dist[v][0], dist[u][1]) * 2 + 1);
            ans = min(ans, max(dist[u][0], dist[v][1]) * 2 + 1);
        }
    }
    cout << ans << "\n";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 55 ms 15112 KB Output is correct
3 Correct 55 ms 15440 KB Output is correct
4 Correct 54 ms 15188 KB Output is correct
5 Correct 56 ms 15184 KB Output is correct
6 Correct 57 ms 15184 KB Output is correct
7 Correct 56 ms 15188 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 2 ms 600 KB Output is correct
9 Correct 1 ms 600 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 1 ms 404 KB Output is correct
13 Correct 1 ms 600 KB Output is correct
14 Correct 2 ms 600 KB Output is correct
15 Correct 2 ms 604 KB Output is correct
16 Correct 2 ms 604 KB Output is correct
17 Correct 2 ms 604 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 2 ms 600 KB Output is correct
9 Correct 1 ms 600 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 1 ms 404 KB Output is correct
13 Correct 1 ms 600 KB Output is correct
14 Correct 2 ms 600 KB Output is correct
15 Correct 2 ms 604 KB Output is correct
16 Correct 2 ms 604 KB Output is correct
17 Correct 2 ms 604 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 604 KB Output is correct
20 Correct 1 ms 604 KB Output is correct
21 Correct 1 ms 604 KB Output is correct
22 Correct 1 ms 624 KB Output is correct
23 Correct 1 ms 604 KB Output is correct
24 Correct 2 ms 600 KB Output is correct
25 Correct 1 ms 604 KB Output is correct
26 Correct 2 ms 488 KB Output is correct
27 Correct 2 ms 600 KB Output is correct
28 Correct 2 ms 604 KB Output is correct
29 Correct 2 ms 604 KB Output is correct
30 Correct 2 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 55 ms 15112 KB Output is correct
3 Correct 55 ms 15440 KB Output is correct
4 Correct 54 ms 15188 KB Output is correct
5 Correct 56 ms 15184 KB Output is correct
6 Correct 57 ms 15184 KB Output is correct
7 Correct 56 ms 15188 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 348 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 2 ms 600 KB Output is correct
17 Correct 1 ms 600 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 1 ms 604 KB Output is correct
20 Correct 1 ms 404 KB Output is correct
21 Correct 1 ms 600 KB Output is correct
22 Correct 2 ms 600 KB Output is correct
23 Correct 2 ms 604 KB Output is correct
24 Correct 2 ms 604 KB Output is correct
25 Correct 2 ms 604 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 1 ms 604 KB Output is correct
28 Correct 1 ms 604 KB Output is correct
29 Correct 1 ms 604 KB Output is correct
30 Correct 1 ms 624 KB Output is correct
31 Correct 1 ms 604 KB Output is correct
32 Correct 2 ms 600 KB Output is correct
33 Correct 1 ms 604 KB Output is correct
34 Correct 2 ms 488 KB Output is correct
35 Correct 2 ms 600 KB Output is correct
36 Correct 2 ms 604 KB Output is correct
37 Correct 2 ms 604 KB Output is correct
38 Correct 2 ms 604 KB Output is correct
39 Correct 149 ms 19540 KB Output is correct
40 Correct 104 ms 18772 KB Output is correct
41 Correct 103 ms 18772 KB Output is correct
42 Correct 104 ms 18772 KB Output is correct
43 Correct 104 ms 18772 KB Output is correct
44 Correct 102 ms 18772 KB Output is correct
45 Correct 135 ms 18516 KB Output is correct
46 Correct 112 ms 18772 KB Output is correct
47 Correct 111 ms 18768 KB Output is correct
48 Correct 121 ms 18568 KB Output is correct
49 Correct 153 ms 19532 KB Output is correct
50 Correct 149 ms 19280 KB Output is correct
51 Correct 130 ms 19280 KB Output is correct
52 Correct 257 ms 25176 KB Output is correct
53 Correct 209 ms 23952 KB Output is correct
54 Correct 191 ms 23776 KB Output is correct
55 Correct 217 ms 24144 KB Output is correct
56 Correct 298 ms 27988 KB Output is correct
57 Correct 283 ms 28152 KB Output is correct
58 Correct 269 ms 29268 KB Output is correct
59 Correct 263 ms 29272 KB Output is correct
60 Correct 285 ms 29008 KB Output is correct
61 Correct 288 ms 28752 KB Output is correct
62 Correct 247 ms 27732 KB Output is correct
63 Correct 243 ms 28012 KB Output is correct
64 Correct 238 ms 28072 KB Output is correct
65 Correct 235 ms 27972 KB Output is correct
66 Correct 277 ms 28072 KB Output is correct
67 Correct 273 ms 28332 KB Output is correct