Submission #1026093

# Submission time Handle Problem Language Result Execution time Memory
1026093 2024-07-17T14:38:21 Z hotboy2703 Sky Walking (IOI19_walk) C++17
24 / 100
1113 ms 229292 KB
#include "walk.h"
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define pll pair <ll,ll>
#define fi first
#define se second
#define MP make_pair
#define sz(a) (ll((a).size()))
#define BIT(mask,i) (((mask) >> (i))&1)
#define MASK(i) (1LL << (i))
struct walk{
    ll l,r,y;
};
vector <walk> all;
const ll MAXN = 1e5 + 100;
const ll INF = 1e18;
vector <pll> g[MAXN*10];
ll dist[MAXN*10];
ll dijkstra(ll s,ll t){
    memset(dist,0x3f,sizeof dist);
    dist[s] = 0;
    priority_queue <pll,vector <pll> ,greater <> > q;
    q.push(MP(dist[s],s));
    while (!q.empty()){
        auto u = q.top().se;
        ll val = q.top().fi;
        q.pop();
        if (dist[u] != val)continue;
        for (auto tmp:g[u]){
            ll v = tmp.fi,w = tmp.se;
            if (dist[u] + w < dist[v]){
                dist[v] = dist[u] + w;
                q.push(MP(dist[v],v));
            }
        }
    }
    if (dist[t] >=INF)dist[t] = -1;
    return dist[t];
}
long long min_distance(std::vector<int> x, std::vector<int> h, std::vector<int> l, std::vector<int> r, std::vector<int> y, int S, int G){
    ll m = sz(l);
    ll n = sz(x);
    for (ll i = 0;i < m;i ++){
        all.push_back({l[i],r[i],y[i]});
    }
    sort(all.begin(),all.end(),[](walk a1,walk a2){return a1.y>a2.y;});
    vector <ll> order;
    order.resize(n);
    iota(order.begin(),order.end(),0);
    sort(order.begin(),order.end(),[&](ll x,ll y){return h[x] > h[y];});
//    cout<<"OK"<<endl;
    vector <pll> vertices;
    S=x[S],G=x[G];
    vertices.push_back(MP(S,0));
    vertices.push_back(MP(G,0));
//    return -1;
    {
        set <ll> s;
        s.insert(-1);
        s.insert(n);
        for (ll i = 0,ptr = 0;i < m;i ++){
//            cout<<i<<'\n';
//            if (i % 1000==0)cout<<i<<endl;
            while (ptr < sz(order) && h[order[ptr]] >= all[i].y){
                s.insert(order[ptr]);
                ptr++;
            }

            vector <ll> tmp;
            for (auto it = s.lower_bound(all[i].l);*it <= all[i].r;it ++){
                tmp.push_back(x[*it]);
            }
//            assert(sz(tmp) <= 10);
            for (auto x:tmp)vertices.push_back(MP(x,all[i].y));
        }
    }
//    if (n==100000)return -1;
    sort(vertices.begin(),vertices.end());
//    for (auto x:vertices){
//        cout<<x.fi<<' '<<x.se<<endl;
//    }
    auto get_id = [&](pll x){
        return lower_bound(vertices.begin(),vertices.end(),x)-vertices.begin();
    };
    auto add_edge = [&](pll x,pll y){
        ll x1 = get_id(x);
        ll y1 = get_id(y);
        ll w = abs(x.fi-y.fi)+abs(x.se-y.se);
        g[x1].push_back(MP(y1,w));
        g[y1].push_back(MP(x1,w));
    };
    {
        set <ll> s;
        s.insert(-1);
        s.insert(n);
        for (ll i = 0,ptr = 0;i < m;i ++){
            while (ptr < sz(order) && h[order[ptr]] >= all[i].y){
                s.insert(order[ptr]);
                ptr++;
            }
            vector <ll> tmp;
            for (auto it = s.lower_bound(all[i].l);*it <= all[i].r;it ++){
                tmp.push_back(x[*it]);
            }
//            cout<<sz(tmp)<<'\n';
            for (ll j = 0;j + 1 < sz(tmp);j ++){
                add_edge(MP(tmp[j],all[i].y),MP(tmp[j+1],all[i].y));
            }
        }
    }
    for (ll i = 0;i + 1 < sz(vertices);i ++){
        if (vertices[i].fi == vertices[i+1].fi)add_edge(vertices[i],vertices[i+1]);
    }
    return dijkstra(get_id(MP(S,0)),get_id(MP(G,0)));
}

# Verdict Execution time Memory Grader output
1 Correct 14 ms 31580 KB Output is correct
2 Correct 13 ms 31580 KB Output is correct
3 Correct 13 ms 31580 KB Output is correct
4 Correct 13 ms 31580 KB Output is correct
5 Correct 14 ms 31832 KB Output is correct
6 Correct 16 ms 31836 KB Output is correct
7 Correct 14 ms 31716 KB Output is correct
8 Correct 13 ms 31768 KB Output is correct
9 Correct 13 ms 31808 KB Output is correct
10 Correct 14 ms 31832 KB Output is correct
11 Correct 14 ms 31580 KB Output is correct
12 Correct 14 ms 31580 KB Output is correct
13 Correct 12 ms 31764 KB Output is correct
14 Correct 15 ms 31580 KB Output is correct
15 Correct 13 ms 31580 KB Output is correct
16 Correct 13 ms 31716 KB Output is correct
17 Correct 14 ms 31836 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 31832 KB Output is correct
2 Correct 13 ms 31580 KB Output is correct
3 Correct 733 ms 107284 KB Output is correct
4 Correct 771 ms 110248 KB Output is correct
5 Correct 519 ms 98720 KB Output is correct
6 Correct 442 ms 90804 KB Output is correct
7 Correct 523 ms 98716 KB Output is correct
8 Correct 954 ms 126404 KB Output is correct
9 Correct 628 ms 99752 KB Output is correct
10 Correct 1113 ms 139324 KB Output is correct
11 Correct 405 ms 74168 KB Output is correct
12 Correct 327 ms 57272 KB Output is correct
13 Correct 909 ms 125944 KB Output is correct
14 Correct 191 ms 55992 KB Output is correct
15 Correct 211 ms 56488 KB Output is correct
16 Correct 215 ms 57884 KB Output is correct
17 Correct 226 ms 57016 KB Output is correct
18 Correct 138 ms 63576 KB Output is correct
19 Correct 19 ms 32924 KB Output is correct
20 Correct 78 ms 43784 KB Output is correct
21 Correct 223 ms 57088 KB Output is correct
22 Correct 210 ms 56176 KB Output is correct
23 Correct 193 ms 63720 KB Output is correct
24 Correct 220 ms 57144 KB Output is correct
25 Correct 280 ms 57604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 101 ms 44832 KB Output is correct
2 Runtime error 710 ms 229292 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 101 ms 44832 KB Output is correct
2 Runtime error 710 ms 229292 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 14 ms 31580 KB Output is correct
2 Correct 13 ms 31580 KB Output is correct
3 Correct 13 ms 31580 KB Output is correct
4 Correct 13 ms 31580 KB Output is correct
5 Correct 14 ms 31832 KB Output is correct
6 Correct 16 ms 31836 KB Output is correct
7 Correct 14 ms 31716 KB Output is correct
8 Correct 13 ms 31768 KB Output is correct
9 Correct 13 ms 31808 KB Output is correct
10 Correct 14 ms 31832 KB Output is correct
11 Correct 14 ms 31580 KB Output is correct
12 Correct 14 ms 31580 KB Output is correct
13 Correct 12 ms 31764 KB Output is correct
14 Correct 15 ms 31580 KB Output is correct
15 Correct 13 ms 31580 KB Output is correct
16 Correct 13 ms 31716 KB Output is correct
17 Correct 14 ms 31836 KB Output is correct
18 Correct 14 ms 31832 KB Output is correct
19 Correct 13 ms 31580 KB Output is correct
20 Correct 733 ms 107284 KB Output is correct
21 Correct 771 ms 110248 KB Output is correct
22 Correct 519 ms 98720 KB Output is correct
23 Correct 442 ms 90804 KB Output is correct
24 Correct 523 ms 98716 KB Output is correct
25 Correct 954 ms 126404 KB Output is correct
26 Correct 628 ms 99752 KB Output is correct
27 Correct 1113 ms 139324 KB Output is correct
28 Correct 405 ms 74168 KB Output is correct
29 Correct 327 ms 57272 KB Output is correct
30 Correct 909 ms 125944 KB Output is correct
31 Correct 191 ms 55992 KB Output is correct
32 Correct 211 ms 56488 KB Output is correct
33 Correct 215 ms 57884 KB Output is correct
34 Correct 226 ms 57016 KB Output is correct
35 Correct 138 ms 63576 KB Output is correct
36 Correct 19 ms 32924 KB Output is correct
37 Correct 78 ms 43784 KB Output is correct
38 Correct 223 ms 57088 KB Output is correct
39 Correct 210 ms 56176 KB Output is correct
40 Correct 193 ms 63720 KB Output is correct
41 Correct 220 ms 57144 KB Output is correct
42 Correct 280 ms 57604 KB Output is correct
43 Correct 101 ms 44832 KB Output is correct
44 Runtime error 710 ms 229292 KB Execution killed with signal 11
45 Halted 0 ms 0 KB -