Submission #1096657

# Submission time Handle Problem Language Result Execution time Memory
1096657 2024-10-04T23:54:14 Z azberjibiou Sky Walking (IOI19_walk) C++17
15 / 100
812 ms 100012 KB
#include "walk.h"
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define pb push_back
#define lb lower_bound
#define gibon ios::sync_with_stdio(false); cin.tie(0);
#define fi first
#define se second
#define pii pair<int, int>
#define pll pair<ll, ll>
typedef long long ll;
using namespace std;
const int mxN=100050;
const int mxM=10000;
const int mxK=60;
const ll INF=1e18;
struct line{
    int l, r, h;
};
int N, M;
int pos[mxN], A[mxN];
line B[mxN];
int st, en;
int sidx, eidx;
map <pii, int> vtx;
pii V[12*mxN];
int vidx;
vector <pll> adj[12*mxN];
void input(){
    cin >> N >> M;
    for(int i=0;i<N;i++) cin >> pos[i];
    for(int i=0;i<N;i++) cin >> A[i];
    for(int i=1;i<=M;i++) cin >> B[i].l >> B[i].r >> B[i].h;
    for(int i=1;i<=M;i++) B[i].l=pos[B[i].l], B[i].r=pos[B[i].r];
    cin >> st >> en;
}
void init(vector <int> x, vector <int> h, vector <int> l, vector <int> r, vector <int> y, int s, int g){
    N=x.size(); M=l.size();
    for(int i=0;i<N;i++) pos[i]=x[i];
    for(int i=0;i<N;i++) A[i]=h[i];
    for(int i=1;i<=M;i++) B[i].l=l[i-1], B[i].r=r[i-1], B[i].h=y[i-1];
  	for(int i=1;i<=M;i++) B[i].l=pos[B[i].l], B[i].r=pos[B[i].r];
    st=s, en=g;
}
void add_edge(int a, int b, int c){
    adj[a].emplace_back(b, c);
    adj[b].emplace_back(a, c);
}
void add(vector <int> &v1, int val, pii rng){
    if(val==-1) return;
    if(val>rng.se || val<rng.fi) return;
    v1.push_back(val);
}
int lb(set <int> &s, int val){
    auto it=s.lower_bound(val);
    return (it==s.end() ? -1 : *it);
}
int rb(set <int> &s, int val){
    auto it=s.lower_bound(val+1);
    if(it==s.begin()) return -1;
    it--;
    return *it;
}
void make_graph(){
    set <int> xcr;
    set <pii> fall; // x값, 끝점 index
    vector <pii> hv;
    for(int i=0;i<N;i++) hv.emplace_back(A[i], i);
    sort(all(hv));
    vector <int> turn;
    for(int i=1;i<=M;i++) turn.push_back(i);
    sort(all(turn), [&](int a, int b){return B[a].h>B[b].h;});
    for(int now : turn){
        auto [nl, nr, nh]=B[now];
        while(hv.size() && hv.back().fi>=nh){
            int idx=hv.back().se;
            hv.pop_back();
            xcr.insert(pos[idx]);
        }
        vector <int> cr;
        vector <pii> up; // x값, 끝점 index
        vector <int> down;
        //get up edges
        while(true){
            if(fall.empty()) break;
            auto it=fall.lower_bound(pii(nl, 0));
            if(it==fall.end() || it->fi>nr) break;
            up.push_back(*it);
            fall.erase(it);
        }
        // add down vertices
        add(down, lb(xcr, nl), pii(nl, nr));
        if(nl<=pos[st] && pos[st]<=nr){
            add(down, lb(xcr, pos[st]), pii(nl, nr));
            add(down, rb(xcr, pos[st]), pii(nl, nr));
        }
        if(nl<=pos[en] && pos[en]<=nr){
            add(down, lb(xcr, pos[en]), pii(nl, nr));
            add(down, rb(xcr, pos[en]), pii(nl, nr));
        }
        add(down, rb(xcr, nr), pii(nl, nr));
        sort(all(down));
        down.erase(unique(all(down)), down.end());
        /*
        printf("nl, nr, nh=%d %d %d\n", nl, nr, nh);
        for(int x : down) printf("%d ", x);
        printf("\n");
        printf("xcr: ");
        for(int x : xcr) printf("%d ", x);
        printf("\n");
        */
        //make vertices
        for(int x : down) cr.push_back(x);
        for(auto [x, idx] : up) cr.push_back(x);
        sort(all(cr));
        cr.erase(unique(all(cr)), cr.end());
        for(int i=0;i<cr.size();i++){
            int x=cr[i];
          	if(vtx.count(pii(x, nh))==0){
              	V[vidx]=pii(x, nh);
            	vtx[pii(x, nh)]=vidx++;
            }
            //also make horizontal edges
            if(i-1>=0) add_edge(vtx[pii(x, nh)], vtx[pii(cr[i-1], nh)], cr[i]-cr[i-1]);
        }
        //make up edges
        for(auto [x, num1] : up){
            int num2=vtx[pii(x, nh)];
            add_edge(num1, num2, V[num1].se-nh);
        }
        //make down edges
        for(int x : down){
            fall.insert(pii(x, vtx[pii(x, nh)]));
        }
    }
    //make st and en
    V[vidx]=pii(pos[st], 0);
    vtx[pii(pos[st], 0)]=vidx;
    sidx=vidx++;
    V[vidx]=pii(pos[en], 0);
    vtx[pii(pos[en], 0)]=vidx;
    eidx=vidx++;
    //adding edge for st and en
    auto itst=fall.lower_bound(pii(pos[st], 0));
    if(itst!=fall.end() || itst->fi==pos[st]){
        int nxt=itst->se;
        add_edge(sidx, nxt, V[nxt].se);
    }
    auto iten=fall.lower_bound(pii(pos[en], 0));
    if(iten!=fall.end() || iten->fi==pos[en]){
        int nxt=iten->se;
        add_edge(eidx, nxt, V[nxt].se);
    }
    /*
    for(int i=0;i<vidx;i++) printf("V[%d]=%d %d\n", i, V[i].fi, V[i].se);
    for(int i=0;i<vidx;i++){
        printf("i=%d: ", i);
        for(auto [x, y] : adj[i]) printf("(%lld %lld) ", x, y);
        printf("\n");
    }
    */
}
ll dist[12*mxN];
ll ans;
void dijkstra(){
    for(int i=0;i<vidx;i++) dist[i]=-1;
    priority_queue <pll> pq;
    pq.emplace(0, sidx);
    while(pq.size()){
        auto [x, now]=pq.top();
        pq.pop();
        if(dist[now]!=-1) continue;
        dist[now]=-x;
        for(auto [nxt, val] : adj[now]) pq.emplace(x-val, nxt);
    }
    //for(int i=0;i<vidx;i++) printf("dist[%d]=%lld\n", i, dist[i]);
    ans=dist[eidx];
}
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) {
	init(x, h, l, r, y, s, g);
    make_graph();
    dijkstra();
    return ans;
}
/*
int main(){
    gibon
    input();
    make_graph();
    dijkstra();
    cout << ans;
}
*/
/*
7 7
0 3 5 7 10 12 14
8 7 9 7 6 6 9
0 1 1
0 2 6
0 6 8
2 3 1
2 6 7
3 4 2
4 6 5
1 5
*/

Compilation message

walk.cpp: In function 'void make_graph()':
walk.cpp:119:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  119 |         for(int i=0;i<cr.size();i++){
      |                     ~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 12 ms 28504 KB Output is correct
2 Correct 12 ms 28664 KB Output is correct
3 Correct 12 ms 28508 KB Output is correct
4 Correct 11 ms 28444 KB Output is correct
5 Correct 12 ms 28504 KB Output is correct
6 Correct 12 ms 28508 KB Output is correct
7 Correct 11 ms 28508 KB Output is correct
8 Correct 12 ms 28620 KB Output is correct
9 Correct 14 ms 28508 KB Output is correct
10 Correct 15 ms 28508 KB Output is correct
11 Correct 12 ms 28568 KB Output is correct
12 Correct 12 ms 28508 KB Output is correct
13 Correct 13 ms 28508 KB Output is correct
14 Correct 11 ms 28672 KB Output is correct
15 Incorrect 12 ms 28508 KB Output isn't correct
16 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 11 ms 28508 KB Output is correct
2 Correct 11 ms 28508 KB Output is correct
3 Correct 605 ms 82540 KB Output is correct
4 Correct 670 ms 91816 KB Output is correct
5 Correct 392 ms 77748 KB Output is correct
6 Correct 391 ms 75756 KB Output is correct
7 Correct 379 ms 78008 KB Output is correct
8 Correct 602 ms 84756 KB Output is correct
9 Correct 539 ms 87376 KB Output is correct
10 Correct 646 ms 92352 KB Output is correct
11 Correct 523 ms 78260 KB Output is correct
12 Correct 478 ms 74384 KB Output is correct
13 Correct 736 ms 94100 KB Output is correct
14 Incorrect 331 ms 70668 KB Output isn't correct
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 160 ms 44116 KB Output is correct
2 Correct 628 ms 89392 KB Output is correct
3 Correct 702 ms 91212 KB Output is correct
4 Correct 789 ms 100012 KB Output is correct
5 Correct 772 ms 99928 KB Output is correct
6 Correct 763 ms 96780 KB Output is correct
7 Correct 344 ms 69848 KB Output is correct
8 Correct 420 ms 74628 KB Output is correct
9 Correct 656 ms 93996 KB Output is correct
10 Correct 357 ms 74900 KB Output is correct
11 Correct 28 ms 33220 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 160 ms 44116 KB Output is correct
2 Correct 628 ms 89392 KB Output is correct
3 Correct 702 ms 91212 KB Output is correct
4 Correct 789 ms 100012 KB Output is correct
5 Correct 772 ms 99928 KB Output is correct
6 Correct 763 ms 96780 KB Output is correct
7 Correct 344 ms 69848 KB Output is correct
8 Correct 420 ms 74628 KB Output is correct
9 Correct 656 ms 93996 KB Output is correct
10 Correct 357 ms 74900 KB Output is correct
11 Correct 28 ms 33220 KB Output is correct
12 Correct 676 ms 91436 KB Output is correct
13 Incorrect 812 ms 99744 KB Output isn't correct
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 12 ms 28504 KB Output is correct
2 Correct 12 ms 28664 KB Output is correct
3 Correct 12 ms 28508 KB Output is correct
4 Correct 11 ms 28444 KB Output is correct
5 Correct 12 ms 28504 KB Output is correct
6 Correct 12 ms 28508 KB Output is correct
7 Correct 11 ms 28508 KB Output is correct
8 Correct 12 ms 28620 KB Output is correct
9 Correct 14 ms 28508 KB Output is correct
10 Correct 15 ms 28508 KB Output is correct
11 Correct 12 ms 28568 KB Output is correct
12 Correct 12 ms 28508 KB Output is correct
13 Correct 13 ms 28508 KB Output is correct
14 Correct 11 ms 28672 KB Output is correct
15 Incorrect 12 ms 28508 KB Output isn't correct
16 Halted 0 ms 0 KB -