답안 #1047948

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1047948 2024-08-07T18:08:45 Z boyliguanhan Sky Walking (IOI19_walk) C++17
100 / 100
1473 ms 201696 KB
#include "walk.h"
#include<bits/stdc++.h>
using namespace std;
typedef vector<int> VI;
map<int,int>pos[100100];
vector<pair<int,int>> adj[1<<20];
int CC;
void AE(int a,int b,int c){
    adj[a].push_back({b,c});
    adj[b].push_back({a,c});
}
int whatpos(int i,int j){
    if(pos[i].count(j))
        return pos[i][j];
    pos[i][j]=++CC;
    auto it=pos[i].find(j);
    if(it!=pos[i].begin())
        AE(prev(it)->second,CC,it->first-prev(it)->first);
    if(next(it)!=pos[i].end())
        AE(next(it)->second,CC,next(it)->first-it->first);
    return CC;
}
long long dis[1<<20];
long long djik(int a,int b){
    memset(dis,9,sizeof dis);
    priority_queue<pair<long long,int>,vector<pair<long long,int>>,greater<>> pq;
    pq.push({0,a});
    dis[a]=0;
    while(pq.size()){
        auto[d,x]=pq.top();
        pq.pop();
        if(d-dis[x])continue;
        for(auto[v,w]:adj[x])
            if(dis[v]>d+w)
                pq.push({dis[v]=d+w,v});
    }
    return dis[b]<dis[0]?dis[b]:-1;
}
set<int>intersection[1<<20];
map<int,int>lft,rt;
void makestuf(VI h,int pos){
    lft.clear();
    rt.clear();
    int n=h.size();
    for(int i=0;i<=pos;i++) {
        lft[h[i]]=i;
        while(lft.begin()->first<h[i])
            lft.erase(lft.begin());
    }
    for(int i=n;i-->pos;){
        rt[h[i]]=i;
        while(rt.begin()->first<h[i])
            rt.erase(rt.begin());
    }
}
long long min_distance(VI x,VI h,VI l,VI r,VI y,int s,int g) {
    int m=l.size();
    makestuf(h,s);
    for(int i=0;i<m;i++)
        if(l[i]<s&&r[i]>s) {
            int A=lft.lower_bound(y[i])->second;
            int B=rt.lower_bound(y[i])->second;
            assert(A>=l[i]);
            assert(B<=r[i]);
            if(A-l[i])
                l.push_back(l[i]),
                r.push_back(l[i]=A),
                y.push_back(y[i]);
            if(B-r[i])
                r.push_back(r[i]),
                l.push_back(r[i]=B),
                y.push_back(y[i]);
        }
    m=l.size();
    makestuf(h,g);
    for(int i=0;i<m;i++)
        if(l[i]<g&&r[i]>g) {
            int A=lft.lower_bound(y[i])->second;
            int B=rt.lower_bound(y[i])->second;
            assert(A>=l[i]);
            assert(B<=r[i]);
            if(A-l[i])
                l.push_back(l[i]),
                r.push_back(l[i]=A),
                y.push_back(y[i]);
            if(B-r[i])
                r.push_back(r[i]),
                l.push_back(r[i]=B),
                y.push_back(y[i]);
        }
    m=l.size();
    vector<pair<int,int>> endpts;
    for(int i=0;i<m;i++) if(l[i]-r[i])
        endpts.push_back({l[i],i}),
        endpts.push_back({r[i],i}),
        whatpos(l[i],y[i]),whatpos(r[i],y[i]);
    sort(endpts.begin(),endpts.end());
    set<pair<int,int>> active;
    for(auto[b,i]:endpts){
        int pos=y[i];
        if(active.lower_bound({pos,0})!=active.begin()){
            auto it=--active.lower_bound({pos,0});
            intersection[it->second].insert(b);
            whatpos(b,it->first);
        }
        if(active.count({pos,i}))
            active.erase({pos,i});
        else active.insert({pos,i});
    }
    for(int i=0;i<m;i++){
        if(l[i]==r[i])continue;
        intersection[i].erase(l[i]);
        intersection[i].insert(r[i]);
        int prvind=whatpos(l[i],y[i]),prvpos=x[l[i]];
        for(auto j:intersection[i])
            AE(prvind,whatpos(j,y[i]),x[j]-prvpos),
            prvind=whatpos(j,y[i]),prvpos=x[j];
    }
    return djik(whatpos(s,0),whatpos(g,0));
}
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 87128 KB Output is correct
2 Correct 11 ms 87132 KB Output is correct
3 Correct 11 ms 87132 KB Output is correct
4 Correct 11 ms 87132 KB Output is correct
5 Correct 12 ms 87148 KB Output is correct
6 Correct 11 ms 87128 KB Output is correct
7 Correct 11 ms 87132 KB Output is correct
8 Correct 12 ms 87128 KB Output is correct
9 Correct 12 ms 87132 KB Output is correct
10 Correct 11 ms 87132 KB Output is correct
11 Correct 11 ms 87168 KB Output is correct
12 Correct 11 ms 87132 KB Output is correct
13 Correct 11 ms 87232 KB Output is correct
14 Correct 12 ms 87132 KB Output is correct
15 Correct 12 ms 87168 KB Output is correct
16 Correct 12 ms 87132 KB Output is correct
17 Correct 11 ms 87128 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 87132 KB Output is correct
2 Correct 12 ms 87216 KB Output is correct
3 Correct 490 ms 144676 KB Output is correct
4 Correct 342 ms 142888 KB Output is correct
5 Correct 217 ms 128960 KB Output is correct
6 Correct 205 ms 127168 KB Output is correct
7 Correct 240 ms 129216 KB Output is correct
8 Correct 482 ms 148200 KB Output is correct
9 Correct 286 ms 139892 KB Output is correct
10 Correct 365 ms 144676 KB Output is correct
11 Correct 286 ms 133040 KB Output is correct
12 Correct 184 ms 116928 KB Output is correct
13 Correct 359 ms 145992 KB Output is correct
14 Correct 175 ms 118976 KB Output is correct
15 Correct 180 ms 118580 KB Output is correct
16 Correct 181 ms 119916 KB Output is correct
17 Correct 178 ms 118408 KB Output is correct
18 Correct 443 ms 127680 KB Output is correct
19 Correct 18 ms 88664 KB Output is correct
20 Correct 66 ms 102556 KB Output is correct
21 Correct 150 ms 118308 KB Output is correct
22 Correct 142 ms 116164 KB Output is correct
23 Correct 333 ms 127424 KB Output is correct
24 Correct 183 ms 117980 KB Output is correct
25 Correct 152 ms 118364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 71 ms 99016 KB Output is correct
2 Correct 673 ms 157348 KB Output is correct
3 Correct 619 ms 157632 KB Output is correct
4 Correct 521 ms 156860 KB Output is correct
5 Correct 604 ms 159212 KB Output is correct
6 Correct 571 ms 154528 KB Output is correct
7 Correct 213 ms 122524 KB Output is correct
8 Correct 154 ms 116932 KB Output is correct
9 Correct 571 ms 149192 KB Output is correct
10 Correct 284 ms 121792 KB Output is correct
11 Correct 17 ms 88984 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 71 ms 99016 KB Output is correct
2 Correct 673 ms 157348 KB Output is correct
3 Correct 619 ms 157632 KB Output is correct
4 Correct 521 ms 156860 KB Output is correct
5 Correct 604 ms 159212 KB Output is correct
6 Correct 571 ms 154528 KB Output is correct
7 Correct 213 ms 122524 KB Output is correct
8 Correct 154 ms 116932 KB Output is correct
9 Correct 571 ms 149192 KB Output is correct
10 Correct 284 ms 121792 KB Output is correct
11 Correct 17 ms 88984 KB Output is correct
12 Correct 581 ms 157632 KB Output is correct
13 Correct 442 ms 155204 KB Output is correct
14 Correct 621 ms 158916 KB Output is correct
15 Correct 385 ms 147392 KB Output is correct
16 Correct 389 ms 143832 KB Output is correct
17 Correct 442 ms 155584 KB Output is correct
18 Correct 419 ms 147392 KB Output is correct
19 Correct 381 ms 143812 KB Output is correct
20 Correct 270 ms 121536 KB Output is correct
21 Correct 33 ms 91140 KB Output is correct
22 Correct 351 ms 141688 KB Output is correct
23 Correct 296 ms 138732 KB Output is correct
24 Correct 203 ms 124544 KB Output is correct
25 Correct 302 ms 134016 KB Output is correct
26 Correct 141 ms 115680 KB Output is correct
27 Correct 644 ms 158900 KB Output is correct
28 Correct 399 ms 154572 KB Output is correct
29 Correct 597 ms 153016 KB Output is correct
30 Correct 239 ms 122568 KB Output is correct
31 Correct 540 ms 149144 KB Output is correct
32 Correct 211 ms 120168 KB Output is correct
33 Correct 196 ms 118968 KB Output is correct
34 Correct 327 ms 124104 KB Output is correct
35 Correct 258 ms 126852 KB Output is correct
36 Correct 181 ms 121056 KB Output is correct
37 Correct 154 ms 118308 KB Output is correct
38 Correct 137 ms 116152 KB Output is correct
39 Correct 332 ms 127408 KB Output is correct
40 Correct 160 ms 117980 KB Output is correct
41 Correct 158 ms 118272 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 87128 KB Output is correct
2 Correct 11 ms 87132 KB Output is correct
3 Correct 11 ms 87132 KB Output is correct
4 Correct 11 ms 87132 KB Output is correct
5 Correct 12 ms 87148 KB Output is correct
6 Correct 11 ms 87128 KB Output is correct
7 Correct 11 ms 87132 KB Output is correct
8 Correct 12 ms 87128 KB Output is correct
9 Correct 12 ms 87132 KB Output is correct
10 Correct 11 ms 87132 KB Output is correct
11 Correct 11 ms 87168 KB Output is correct
12 Correct 11 ms 87132 KB Output is correct
13 Correct 11 ms 87232 KB Output is correct
14 Correct 12 ms 87132 KB Output is correct
15 Correct 12 ms 87168 KB Output is correct
16 Correct 12 ms 87132 KB Output is correct
17 Correct 11 ms 87128 KB Output is correct
18 Correct 11 ms 87132 KB Output is correct
19 Correct 12 ms 87216 KB Output is correct
20 Correct 490 ms 144676 KB Output is correct
21 Correct 342 ms 142888 KB Output is correct
22 Correct 217 ms 128960 KB Output is correct
23 Correct 205 ms 127168 KB Output is correct
24 Correct 240 ms 129216 KB Output is correct
25 Correct 482 ms 148200 KB Output is correct
26 Correct 286 ms 139892 KB Output is correct
27 Correct 365 ms 144676 KB Output is correct
28 Correct 286 ms 133040 KB Output is correct
29 Correct 184 ms 116928 KB Output is correct
30 Correct 359 ms 145992 KB Output is correct
31 Correct 175 ms 118976 KB Output is correct
32 Correct 180 ms 118580 KB Output is correct
33 Correct 181 ms 119916 KB Output is correct
34 Correct 178 ms 118408 KB Output is correct
35 Correct 443 ms 127680 KB Output is correct
36 Correct 18 ms 88664 KB Output is correct
37 Correct 66 ms 102556 KB Output is correct
38 Correct 150 ms 118308 KB Output is correct
39 Correct 142 ms 116164 KB Output is correct
40 Correct 333 ms 127424 KB Output is correct
41 Correct 183 ms 117980 KB Output is correct
42 Correct 152 ms 118364 KB Output is correct
43 Correct 71 ms 99016 KB Output is correct
44 Correct 673 ms 157348 KB Output is correct
45 Correct 619 ms 157632 KB Output is correct
46 Correct 521 ms 156860 KB Output is correct
47 Correct 604 ms 159212 KB Output is correct
48 Correct 571 ms 154528 KB Output is correct
49 Correct 213 ms 122524 KB Output is correct
50 Correct 154 ms 116932 KB Output is correct
51 Correct 571 ms 149192 KB Output is correct
52 Correct 284 ms 121792 KB Output is correct
53 Correct 17 ms 88984 KB Output is correct
54 Correct 581 ms 157632 KB Output is correct
55 Correct 442 ms 155204 KB Output is correct
56 Correct 621 ms 158916 KB Output is correct
57 Correct 385 ms 147392 KB Output is correct
58 Correct 389 ms 143832 KB Output is correct
59 Correct 442 ms 155584 KB Output is correct
60 Correct 419 ms 147392 KB Output is correct
61 Correct 381 ms 143812 KB Output is correct
62 Correct 270 ms 121536 KB Output is correct
63 Correct 33 ms 91140 KB Output is correct
64 Correct 351 ms 141688 KB Output is correct
65 Correct 296 ms 138732 KB Output is correct
66 Correct 203 ms 124544 KB Output is correct
67 Correct 302 ms 134016 KB Output is correct
68 Correct 141 ms 115680 KB Output is correct
69 Correct 644 ms 158900 KB Output is correct
70 Correct 399 ms 154572 KB Output is correct
71 Correct 597 ms 153016 KB Output is correct
72 Correct 239 ms 122568 KB Output is correct
73 Correct 540 ms 149144 KB Output is correct
74 Correct 211 ms 120168 KB Output is correct
75 Correct 196 ms 118968 KB Output is correct
76 Correct 327 ms 124104 KB Output is correct
77 Correct 258 ms 126852 KB Output is correct
78 Correct 181 ms 121056 KB Output is correct
79 Correct 154 ms 118308 KB Output is correct
80 Correct 137 ms 116152 KB Output is correct
81 Correct 332 ms 127408 KB Output is correct
82 Correct 160 ms 117980 KB Output is correct
83 Correct 158 ms 118272 KB Output is correct
84 Correct 62 ms 96640 KB Output is correct
85 Correct 659 ms 160608 KB Output is correct
86 Correct 912 ms 178168 KB Output is correct
87 Correct 43 ms 95944 KB Output is correct
88 Correct 50 ms 95516 KB Output is correct
89 Correct 43 ms 96028 KB Output is correct
90 Correct 24 ms 90336 KB Output is correct
91 Correct 13 ms 87128 KB Output is correct
92 Correct 22 ms 89688 KB Output is correct
93 Correct 154 ms 111904 KB Output is correct
94 Correct 36 ms 91340 KB Output is correct
95 Correct 358 ms 144668 KB Output is correct
96 Correct 309 ms 139456 KB Output is correct
97 Correct 206 ms 126144 KB Output is correct
98 Correct 255 ms 133972 KB Output is correct
99 Correct 1473 ms 201696 KB Output is correct
100 Correct 519 ms 157168 KB Output is correct
101 Correct 830 ms 168032 KB Output is correct
102 Correct 223 ms 122952 KB Output is correct
103 Correct 214 ms 119896 KB Output is correct
104 Correct 209 ms 118724 KB Output is correct
105 Correct 296 ms 124188 KB Output is correct
106 Correct 234 ms 121284 KB Output is correct
107 Correct 244 ms 124352 KB Output is correct
108 Correct 34 ms 92496 KB Output is correct
109 Correct 407 ms 140332 KB Output is correct
110 Correct 439 ms 155692 KB Output is correct
111 Correct 455 ms 157840 KB Output is correct
112 Correct 255 ms 126476 KB Output is correct
113 Correct 217 ms 124256 KB Output is correct