Submission #901263

# Submission time Handle Problem Language Result Execution time Memory
901263 2024-01-09T08:21:46 Z abcvuitunggio Sky Walking (IOI19_walk) C++17
24 / 100
1441 ms 441468 KB
#include "walk.h"
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int INF=1e18;
priority_queue <pair <int, int>, vector <pair <int, int>>, greater <pair <int, int>>> q;
vector <int> a[100001],b[100001],V;
vector <pair <int, int>> ke[12000001],ve,nodes;
int n,m,d[12000001],dp[200001],ft[200001][2];
set <int> S;
void add(int i, int j){
    a[i].push_back(j);
    nodes.push_back({i,j});
}
int f(int i, int j){
    return lower_bound(nodes.begin(),nodes.end(),make_pair(i,j))-nodes.begin();
}
void update(int i, int j, int val){
    for (;i<=V.size();i+=i&(-i))
        ft[i][j]=min(ft[i][j],val);
}
int get(int i, int j){
    int res=INF;
    for (;i;i-=i&(-i))
        res=min(res,ft[i][j]);
    return res;
}
int min_distance(vector<int32_t> x, vector<int32_t> h, vector<int32_t> l, vector<int32_t> r, vector<int32_t> y, int32_t s, int32_t g){
    n=x.size(),m=l.size();
    int ch=1;
    for (int i=1;i<n;i++)
        ch&=(h[i]==h[0]);
    if (s>g)
        swap(s,g);
    if (s==0&&g==n-1&&ch){
        vector <pair <int, int>> tmp;
        for (int i=0;i<m;i++){
            tmp.push_back({l[i],r[i]});
            ve.push_back({l[i],y[i]});
            if (r[i]==g)
                ve.push_back({r[i],y[i]});
        }
        sort(tmp.begin(),tmp.end());
        int cur=0;
        for (auto [i,j]:tmp)
            if (cur>=i)
                cur=max(cur,j);
        if (cur<g)
            return -1;
        sort(ve.begin(),ve.end());
        for (auto [i,j]:ve)
            V.push_back(j);
        sort(V.begin(),V.end());
        V.resize(unique(V.begin(),V.end())-V.begin());
        for (int i=0;i<=V.size();i++)
            ft[i][0]=ft[i][1]=INF;
        for (int i=ve.size()-1;i>=0;i--){
            int Y=ve[i].second,j=lower_bound(V.begin(),V.end(),Y)-V.begin()+1;
            if (ve[i].first==g)
                dp[i]=Y;
            else
                dp[i]=min(get(V.size()-j+1,0)-Y,get(j,1)+Y);
            update(V.size()-j+1,0,dp[i]+Y);
            update(j,1,dp[i]-Y);
        }
        return dp[0]+ve[0].second+x[g]-x[s];
    }
    for (int i=0;i<n;i++)
        ve.push_back({-h[i],-i});
    for (int i=0;i<m;i++)
        ve.push_back({-y[i],i+1});
    sort(ve.begin(),ve.end());
    for (auto [i,j]:ve){
        i=-i,j=-j;
        if (j>=0){
            S.insert(j);
            continue;
        }
        j=-j-1;
        for (auto it=S.lower_bound(l[j]);it!=S.end()&&*it<=r[j];it++){
            add(*it,j);
            b[j].push_back(*it);
        }
    }
    add(s,-1);
    add(g,-1);
    sort(nodes.begin(),nodes.end());
    nodes.resize(unique(nodes.begin(),nodes.end())-nodes.begin());
    for (int i=0;i<n;i++)
        for (int j=0;j<(int)a[i].size()-1;j++){
            int u=f(i,a[i][j]),v=f(i,a[i][j+1]),w=abs((a[i][j]>=0?y[a[i][j]]:0)-(a[i][j+1]>=0?y[a[i][j+1]]:0));
            ke[u].push_back({v,w});
            ke[v].push_back({u,w});
        }
    for (int i=0;i<m;i++)
        for (int j=0;j<(int)b[i].size()-1;j++){
            int u=f(b[i][j],i),v=f(b[i][j+1],i),w=x[b[i][j+1]]-x[b[i][j]];
            ke[u].push_back({v,w});
            ke[v].push_back({u,w});
        }
    fill(d,d+nodes.size(),INF);
    d[f(s,-1)]=0;
    q.push({0,f(s,-1)});
    while (!q.empty()){
        auto [du,u]=q.top();
        q.pop();
        if (du!=d[u])
            continue;
        for (auto [v,w]:ke[u])
            if (d[v]>d[u]+w){
                d[v]=d[u]+w;
                q.push({d[v],v});
            }
    }
    return (d[f(g,-1)]==INF?-1:d[f(g,-1)]);
}

Compilation message

walk.cpp: In function 'void update(long long int, long long int, long long int)':
walk.cpp:19:12: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   19 |     for (;i<=V.size();i+=i&(-i))
      |           ~^~~~~~~~~~
walk.cpp: In function 'long long int min_distance(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>, int32_t, int32_t)':
walk.cpp:55:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |         for (int i=0;i<=V.size();i++)
      |                      ~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 90 ms 290900 KB Output is correct
2 Correct 61 ms 290900 KB Output is correct
3 Correct 61 ms 290968 KB Output is correct
4 Correct 61 ms 290856 KB Output is correct
5 Correct 63 ms 291084 KB Output is correct
6 Correct 62 ms 290968 KB Output is correct
7 Correct 61 ms 290896 KB Output is correct
8 Correct 63 ms 290836 KB Output is correct
9 Correct 61 ms 291016 KB Output is correct
10 Correct 63 ms 291152 KB Output is correct
11 Correct 61 ms 290888 KB Output is correct
12 Correct 65 ms 290896 KB Output is correct
13 Correct 62 ms 290908 KB Output is correct
14 Correct 62 ms 290952 KB Output is correct
15 Correct 63 ms 290944 KB Output is correct
16 Correct 61 ms 290900 KB Output is correct
17 Correct 62 ms 291120 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 65 ms 290896 KB Output is correct
2 Correct 61 ms 290900 KB Output is correct
3 Correct 1034 ms 392272 KB Output is correct
4 Correct 997 ms 396716 KB Output is correct
5 Correct 702 ms 382376 KB Output is correct
6 Correct 585 ms 371196 KB Output is correct
7 Correct 714 ms 382692 KB Output is correct
8 Correct 1321 ms 420392 KB Output is correct
9 Correct 791 ms 382772 KB Output is correct
10 Correct 1441 ms 441468 KB Output is correct
11 Correct 522 ms 347320 KB Output is correct
12 Correct 348 ms 323000 KB Output is correct
13 Correct 1218 ms 423084 KB Output is correct
14 Correct 297 ms 323684 KB Output is correct
15 Correct 329 ms 323532 KB Output is correct
16 Correct 318 ms 326840 KB Output is correct
17 Correct 300 ms 324620 KB Output is correct
18 Correct 330 ms 332216 KB Output is correct
19 Correct 69 ms 292556 KB Output is correct
20 Correct 130 ms 305600 KB Output is correct
21 Correct 285 ms 323768 KB Output is correct
22 Correct 359 ms 322580 KB Output is correct
23 Correct 413 ms 332984 KB Output is correct
24 Correct 332 ms 323252 KB Output is correct
25 Correct 323 ms 326328 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 82 ms 294620 KB Output is correct
2 Correct 125 ms 300484 KB Output is correct
3 Correct 130 ms 300536 KB Output is correct
4 Correct 145 ms 302004 KB Output is correct
5 Correct 144 ms 302008 KB Output is correct
6 Correct 153 ms 302516 KB Output is correct
7 Correct 111 ms 298500 KB Output is correct
8 Incorrect 150 ms 302172 KB Output isn't correct
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 82 ms 294620 KB Output is correct
2 Correct 125 ms 300484 KB Output is correct
3 Correct 130 ms 300536 KB Output is correct
4 Correct 145 ms 302004 KB Output is correct
5 Correct 144 ms 302008 KB Output is correct
6 Correct 153 ms 302516 KB Output is correct
7 Correct 111 ms 298500 KB Output is correct
8 Incorrect 150 ms 302172 KB Output isn't correct
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 90 ms 290900 KB Output is correct
2 Correct 61 ms 290900 KB Output is correct
3 Correct 61 ms 290968 KB Output is correct
4 Correct 61 ms 290856 KB Output is correct
5 Correct 63 ms 291084 KB Output is correct
6 Correct 62 ms 290968 KB Output is correct
7 Correct 61 ms 290896 KB Output is correct
8 Correct 63 ms 290836 KB Output is correct
9 Correct 61 ms 291016 KB Output is correct
10 Correct 63 ms 291152 KB Output is correct
11 Correct 61 ms 290888 KB Output is correct
12 Correct 65 ms 290896 KB Output is correct
13 Correct 62 ms 290908 KB Output is correct
14 Correct 62 ms 290952 KB Output is correct
15 Correct 63 ms 290944 KB Output is correct
16 Correct 61 ms 290900 KB Output is correct
17 Correct 62 ms 291120 KB Output is correct
18 Correct 65 ms 290896 KB Output is correct
19 Correct 61 ms 290900 KB Output is correct
20 Correct 1034 ms 392272 KB Output is correct
21 Correct 997 ms 396716 KB Output is correct
22 Correct 702 ms 382376 KB Output is correct
23 Correct 585 ms 371196 KB Output is correct
24 Correct 714 ms 382692 KB Output is correct
25 Correct 1321 ms 420392 KB Output is correct
26 Correct 791 ms 382772 KB Output is correct
27 Correct 1441 ms 441468 KB Output is correct
28 Correct 522 ms 347320 KB Output is correct
29 Correct 348 ms 323000 KB Output is correct
30 Correct 1218 ms 423084 KB Output is correct
31 Correct 297 ms 323684 KB Output is correct
32 Correct 329 ms 323532 KB Output is correct
33 Correct 318 ms 326840 KB Output is correct
34 Correct 300 ms 324620 KB Output is correct
35 Correct 330 ms 332216 KB Output is correct
36 Correct 69 ms 292556 KB Output is correct
37 Correct 130 ms 305600 KB Output is correct
38 Correct 285 ms 323768 KB Output is correct
39 Correct 359 ms 322580 KB Output is correct
40 Correct 413 ms 332984 KB Output is correct
41 Correct 332 ms 323252 KB Output is correct
42 Correct 323 ms 326328 KB Output is correct
43 Correct 82 ms 294620 KB Output is correct
44 Correct 125 ms 300484 KB Output is correct
45 Correct 130 ms 300536 KB Output is correct
46 Correct 145 ms 302004 KB Output is correct
47 Correct 144 ms 302008 KB Output is correct
48 Correct 153 ms 302516 KB Output is correct
49 Correct 111 ms 298500 KB Output is correct
50 Incorrect 150 ms 302172 KB Output isn't correct
51 Halted 0 ms 0 KB -