답안 #1047078

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1047078 2024-08-07T08:38:43 Z vjudge1 Sky Walking (IOI19_walk) C++17
33 / 100
2008 ms 1048576 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[100100];
map<int,int>lft,rt;
void makestuf(vector<int>h,int pos){
    lft.clear();
    rt.clear();
    int n=h.size();
    for(int i=0;i<=pos;i++)
        lft[h[i]]=max(lft[h[i]],i);
    for(int i=pos;i<n;i++)
        if(rt.count(h[i]))
            rt[h[i]]=min(rt[h[i]],i);
        else rt[h[i]]=i;
    auto it=lft.end();
    while(--it!=lft.begin())
        if(it->second>=prev(it)->second)
            it=lft.erase(prev(it));
    it=rt.end();
    while(--it!=rt.begin())
        if(it->second<=prev(it)->second)
            it=rt.erase(prev(it));
}
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) {
            assert(lft.lower_bound(y[i])!=lft.end());
            assert(rt.lower_bound(y[i])!=rt.end());
            int A=lft.lower_bound(y[i])->second;
            int B=rt.lower_bound(y[i])->second;
            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) {
            assert(lft.lower_bound(y[i])!=lft.end());
            assert(rt.lower_bound(y[i])!=rt.end());
            int A=lft.lower_bound(y[i])->second;
            int B=rt.lower_bound(y[i])->second;
            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++)
        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++){
        intersection[i].insert(r[i]);
        intersection[i].erase(l[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 6 ms 42584 KB Output is correct
2 Correct 5 ms 42588 KB Output is correct
3 Correct 5 ms 42584 KB Output is correct
4 Correct 6 ms 42588 KB Output is correct
5 Runtime error 2008 ms 1048576 KB Execution killed with signal 9
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 42584 KB Output is correct
2 Correct 5 ms 42588 KB Output is correct
3 Runtime error 131 ms 122464 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 57 ms 53960 KB Output is correct
2 Correct 680 ms 111032 KB Output is correct
3 Correct 627 ms 111040 KB Output is correct
4 Correct 517 ms 108220 KB Output is correct
5 Correct 638 ms 110508 KB Output is correct
6 Correct 577 ms 105676 KB Output is correct
7 Correct 209 ms 74952 KB Output is correct
8 Correct 127 ms 68260 KB Output is correct
9 Correct 562 ms 100632 KB Output is correct
10 Correct 284 ms 73916 KB Output is correct
11 Correct 12 ms 43412 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 57 ms 53960 KB Output is correct
2 Correct 680 ms 111032 KB Output is correct
3 Correct 627 ms 111040 KB Output is correct
4 Correct 517 ms 108220 KB Output is correct
5 Correct 638 ms 110508 KB Output is correct
6 Correct 577 ms 105676 KB Output is correct
7 Correct 209 ms 74952 KB Output is correct
8 Correct 127 ms 68260 KB Output is correct
9 Correct 562 ms 100632 KB Output is correct
10 Correct 284 ms 73916 KB Output is correct
11 Correct 12 ms 43412 KB Output is correct
12 Correct 578 ms 111180 KB Output is correct
13 Correct 501 ms 109588 KB Output is correct
14 Correct 665 ms 113348 KB Output is correct
15 Correct 382 ms 99112 KB Output is correct
16 Correct 447 ms 98332 KB Output is correct
17 Correct 502 ms 110016 KB Output is correct
18 Correct 387 ms 99008 KB Output is correct
19 Correct 445 ms 98344 KB Output is correct
20 Correct 290 ms 77000 KB Output is correct
21 Correct 88 ms 49224 KB Output is correct
22 Correct 402 ms 95684 KB Output is correct
23 Correct 303 ms 92820 KB Output is correct
24 Correct 216 ms 78528 KB Output is correct
25 Correct 272 ms 88772 KB Output is correct
26 Correct 152 ms 70084 KB Output is correct
27 Correct 687 ms 112272 KB Output is correct
28 Correct 462 ms 108988 KB Output is correct
29 Correct 631 ms 106000 KB Output is correct
30 Correct 277 ms 78276 KB Output is correct
31 Correct 629 ms 103488 KB Output is correct
32 Correct 216 ms 72432 KB Output is correct
33 Correct 190 ms 71088 KB Output is correct
34 Correct 295 ms 77760 KB Output is correct
35 Correct 269 ms 79832 KB Output is correct
36 Correct 180 ms 73956 KB Output is correct
37 Correct 136 ms 71012 KB Output is correct
38 Correct 126 ms 68388 KB Output is correct
39 Correct 330 ms 82620 KB Output is correct
40 Correct 148 ms 70624 KB Output is correct
41 Correct 150 ms 70904 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 42584 KB Output is correct
2 Correct 5 ms 42588 KB Output is correct
3 Correct 5 ms 42584 KB Output is correct
4 Correct 6 ms 42588 KB Output is correct
5 Runtime error 2008 ms 1048576 KB Execution killed with signal 9
6 Halted 0 ms 0 KB -