답안 #1086329

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1086329 2024-09-10T07:51:39 Z pemguimn Passport (JOI23_passport) C++14
100 / 100
663 ms 134200 KB
#include <bits/stdc++.h>
#define int long long
#define pii pair<int, int>
using namespace std;

const int N = 2e5 + 5, NODE = 8e5 + 5, INF = 2e9 + 7;

int n, q, l[N], r[N], ans[N], idn[N];

vector<array<int, 2>> adj[NODE];

void build(int id = 1, int l = 1, int r = n){
    if(l == r){
        idn[l] = id; return;
    }
    int mid = (l + r) / 2;
    build(id * 2, l, mid), build(id * 2 + 1, mid + 1, r);
    adj[id * 2].push_back({id, 0}), adj[id * 2 + 1].push_back({id, 0});
}

void add(int id, int tl, int tr, int l, int r, int p){
    if(r < tl || tr < l) return;
    if(l <= tl && tr <= r) {
        adj[id].push_back({idn[p], 1});
        return;
    }
    int mid = (tl + tr) / 2;
    add(id * 2, tl, mid, l, r, p), add(id * 2 + 1, mid + 1, tr, l, r, p);
}

void dijkstra(vector<int> &d){
    priority_queue<array<int, 2>> pq;
    for(int i = 1; i <= 4 * n; i++){
        if(d[i] < 1e9) pq.push({-d[i], i});
    }

    while(!pq.empty()){
        auto [c, i] = pq.top(); pq.pop();
        c = -c;
        if(c != d[i]) continue;
        for(auto [x, w] : adj[i]){
            if(d[x] > d[i] + w){
                d[x] = d[i] + w;
                pq.push({-d[x], x});
            }
        }
    }
}
signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    cin >> n;
    build(1, 1, n);
    for(int i = 1; i <= n; i++){
        cin >> l[i] >> r[i];
        add(1, 1, n, l[i], r[i], i);
    }


    vector<int> d1(4 * n + 1, INF); d1[idn[1]] = 0; dijkstra(d1);
    vector<int> d2(4 * n + 1, INF); d2[idn[n]] = 0; dijkstra(d2);
    vector<int> d3(4 * n + 1, INF);
    d1[idn[1]] = 1, d2[idn[n]] = 1;
    for(int i = 1; i <= n; i++){
        int x = idn[i];
        d3[x] = min(d3[x], d1[x] + d2[x] - 1);
    }
    dijkstra(d3);
    cin >> q;
    while(q--){
        int x; cin >> x;
        int ans = d3[idn[x]];
        if(ans >= 1e9) cout << -1;
        else cout << ans;
        cout << '\n';
    }
    return 0;
}

Compilation message

passport.cpp: In function 'void dijkstra(std::vector<long long int>&)':
passport.cpp:38:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   38 |         auto [c, i] = pq.top(); pq.pop();
      |              ^
passport.cpp:41:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   41 |         for(auto [x, w] : adj[i]){
      |                  ^
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 19032 KB Output is correct
2 Correct 8 ms 19172 KB Output is correct
3 Correct 8 ms 19036 KB Output is correct
4 Correct 663 ms 120556 KB Output is correct
5 Correct 312 ms 79544 KB Output is correct
6 Correct 186 ms 69316 KB Output is correct
7 Correct 200 ms 66260 KB Output is correct
8 Correct 133 ms 71340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 19036 KB Output is correct
2 Correct 8 ms 19052 KB Output is correct
3 Correct 8 ms 19032 KB Output is correct
4 Correct 9 ms 19264 KB Output is correct
5 Correct 8 ms 19036 KB Output is correct
6 Correct 9 ms 19096 KB Output is correct
7 Correct 9 ms 19096 KB Output is correct
8 Correct 9 ms 19092 KB Output is correct
9 Correct 8 ms 19036 KB Output is correct
10 Correct 8 ms 19036 KB Output is correct
11 Correct 9 ms 19292 KB Output is correct
12 Correct 8 ms 19288 KB Output is correct
13 Correct 8 ms 19292 KB Output is correct
14 Correct 8 ms 19292 KB Output is correct
15 Correct 10 ms 19288 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 19036 KB Output is correct
2 Correct 8 ms 19052 KB Output is correct
3 Correct 8 ms 19032 KB Output is correct
4 Correct 9 ms 19264 KB Output is correct
5 Correct 8 ms 19036 KB Output is correct
6 Correct 9 ms 19096 KB Output is correct
7 Correct 9 ms 19096 KB Output is correct
8 Correct 9 ms 19092 KB Output is correct
9 Correct 8 ms 19036 KB Output is correct
10 Correct 8 ms 19036 KB Output is correct
11 Correct 9 ms 19292 KB Output is correct
12 Correct 8 ms 19288 KB Output is correct
13 Correct 8 ms 19292 KB Output is correct
14 Correct 8 ms 19292 KB Output is correct
15 Correct 10 ms 19288 KB Output is correct
16 Correct 13 ms 20208 KB Output is correct
17 Correct 10 ms 20028 KB Output is correct
18 Correct 11 ms 20316 KB Output is correct
19 Correct 11 ms 20316 KB Output is correct
20 Correct 10 ms 19804 KB Output is correct
21 Correct 10 ms 20000 KB Output is correct
22 Correct 9 ms 19548 KB Output is correct
23 Correct 12 ms 20056 KB Output is correct
24 Correct 11 ms 20060 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 19036 KB Output is correct
2 Correct 8 ms 19052 KB Output is correct
3 Correct 8 ms 19032 KB Output is correct
4 Correct 9 ms 19264 KB Output is correct
5 Correct 8 ms 19036 KB Output is correct
6 Correct 9 ms 19096 KB Output is correct
7 Correct 9 ms 19096 KB Output is correct
8 Correct 9 ms 19092 KB Output is correct
9 Correct 8 ms 19036 KB Output is correct
10 Correct 8 ms 19036 KB Output is correct
11 Correct 9 ms 19292 KB Output is correct
12 Correct 8 ms 19288 KB Output is correct
13 Correct 8 ms 19292 KB Output is correct
14 Correct 8 ms 19292 KB Output is correct
15 Correct 10 ms 19288 KB Output is correct
16 Correct 13 ms 20208 KB Output is correct
17 Correct 10 ms 20028 KB Output is correct
18 Correct 11 ms 20316 KB Output is correct
19 Correct 11 ms 20316 KB Output is correct
20 Correct 10 ms 19804 KB Output is correct
21 Correct 10 ms 20000 KB Output is correct
22 Correct 9 ms 19548 KB Output is correct
23 Correct 12 ms 20056 KB Output is correct
24 Correct 11 ms 20060 KB Output is correct
25 Correct 9 ms 19036 KB Output is correct
26 Correct 8 ms 19036 KB Output is correct
27 Correct 12 ms 20060 KB Output is correct
28 Correct 13 ms 19992 KB Output is correct
29 Correct 10 ms 19972 KB Output is correct
30 Correct 10 ms 19804 KB Output is correct
31 Correct 12 ms 19804 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 19032 KB Output is correct
2 Correct 8 ms 19172 KB Output is correct
3 Correct 8 ms 19036 KB Output is correct
4 Correct 663 ms 120556 KB Output is correct
5 Correct 312 ms 79544 KB Output is correct
6 Correct 186 ms 69316 KB Output is correct
7 Correct 200 ms 66260 KB Output is correct
8 Correct 133 ms 71340 KB Output is correct
9 Correct 9 ms 19036 KB Output is correct
10 Correct 8 ms 19052 KB Output is correct
11 Correct 8 ms 19032 KB Output is correct
12 Correct 9 ms 19264 KB Output is correct
13 Correct 8 ms 19036 KB Output is correct
14 Correct 9 ms 19096 KB Output is correct
15 Correct 9 ms 19096 KB Output is correct
16 Correct 9 ms 19092 KB Output is correct
17 Correct 8 ms 19036 KB Output is correct
18 Correct 8 ms 19036 KB Output is correct
19 Correct 9 ms 19292 KB Output is correct
20 Correct 8 ms 19288 KB Output is correct
21 Correct 8 ms 19292 KB Output is correct
22 Correct 8 ms 19292 KB Output is correct
23 Correct 10 ms 19288 KB Output is correct
24 Correct 13 ms 20208 KB Output is correct
25 Correct 10 ms 20028 KB Output is correct
26 Correct 11 ms 20316 KB Output is correct
27 Correct 11 ms 20316 KB Output is correct
28 Correct 10 ms 19804 KB Output is correct
29 Correct 10 ms 20000 KB Output is correct
30 Correct 9 ms 19548 KB Output is correct
31 Correct 12 ms 20056 KB Output is correct
32 Correct 11 ms 20060 KB Output is correct
33 Correct 9 ms 19036 KB Output is correct
34 Correct 8 ms 19036 KB Output is correct
35 Correct 12 ms 20060 KB Output is correct
36 Correct 13 ms 19992 KB Output is correct
37 Correct 10 ms 19972 KB Output is correct
38 Correct 10 ms 19804 KB Output is correct
39 Correct 12 ms 19804 KB Output is correct
40 Correct 628 ms 127500 KB Output is correct
41 Correct 327 ms 80328 KB Output is correct
42 Correct 432 ms 132220 KB Output is correct
43 Correct 426 ms 134200 KB Output is correct
44 Correct 216 ms 69580 KB Output is correct
45 Correct 237 ms 82236 KB Output is correct
46 Correct 121 ms 43260 KB Output is correct
47 Correct 439 ms 88340 KB Output is correct
48 Correct 282 ms 99908 KB Output is correct