답안 #296182

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
296182 2020-09-10T11:44:18 Z Noam13 Sky Walking (IOI19_walk) C++14
24 / 100
2183 ms 771576 KB
#include "walk.h"
#include <bits/stdc++.h>
#define int int64_t
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define ii pair<int, int>
#define vii vector<ii>
#define vvii vector<vii>
#define x first
#define y second
#define all(a) a.begin(), a.end()
#define loop(i,s,e) for(int i=s;i<e;++i)
#define loopr(i,s,e) for(int i=e-1;i>=s;--i)
#define chkmin(a,b) a = min(a,b)
#define chkmax(a,b) a = max(a,b)
using namespace std;
const int INF = 2e18;
struct SEG{
	int n, sz;
    vii a;
    SEG(vi& arr): n(arr.size()){
        for(sz=1;sz<n;sz*=2);
        a.resize(2*sz);
        loop(i,0,n) a[i+sz] = {arr[i],i};
        loopr(i,1,sz){
            a[i] = max(a[2*i], a[2*i+1]);
        }
    }
    ii query(int l, int r){
        ii best = {0, -1};
        for(l+=sz, r+=sz; l<=r; l/=2, r/=2){
            if (l%2) chkmax(best, a[l++]);
            if (r%2==0) chkmax(best, a[r--]);
        }
        return best;
    }
};
int n,m;
vvi inter;
vi h;
vvi vec;
void solve(SEG &seg, int a, int b, int x, int i){
    if (a>b) return ;
    ii v = seg.query(a,b);
    if (v.x < x) return ;
    inter[v.y].pb(x);
    vec[i].pb(v.y);
    solve(seg, a, v.y-1, x, i);
    solve(seg, v.y+1, b, x, i);
}
const int MAXN = 2e6 + 10;
long long 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 e) {
    n = x.size(), m = l.size();
    h.resize(n); loop(i,0,n) h[i] = H[i];
    SEG seg(h);
    inter.resize(n);
    vec.resize(m);
    loop(i,0,m){
        solve(seg, l[i], r[i], y[i], i);
        sort(all(vec[i]));
        //cout<<"SEG: "<<i<<" : ";
        //for(auto v:vec[i]) cout<<v<<" "; cout<<endl;
    }
    int cnt = 0;
    vii g[MAXN];
    loop(i,0,MAXN) g[i].clear();
    map<ii, int> conv;
    loop(i,0,n){
        inter[i].pb(0);
        sort(all(inter[i]));
        inter[i].resize(unique(all(inter[i]))-inter[i].begin());
        int last = -1;
        //cout<<"INTER: "<<i<<"  : ";
        for(auto x:inter[i]){
            //cout<<x<<endl;
            if (last!=-1){
                int dy = x - last;
                g[cnt].pb({cnt-1, dy});
                g[cnt-1].pb({cnt, dy});
            }
            conv[{i, x}] = cnt++;
            last = x;
        }
        //cout<<endl;
    }
    loop(i,0,m){
        int r = vec[i].size();
        loop(j,0,r-1){
            int a = vec[i][j], b = vec[i][j+1];
            int dx = abs(x[b] - x[a]);
            a = conv[{a, y[i]}], b = conv[{b, y[i]}];
            g[a].pb({b,dx});
            g[b].pb({a,dx});
        }
    }
    /*vii back(cnt);
    for(auto p:conv){
        //cout<<p.y<<" = "<< p.x.x<<", "<<p.x.y<<endl;
        back[p.y] = p.x;
    }*/
    s = conv[{s, 0}], e = conv[{e, 0}];
    vi dist(cnt, INF); dist[s] = 0;
    priority_queue<ii> q; q.push({0,s});
    while(q.size()){
        int cur =q.top().y, d = -q.top().x; q.pop();
        if (dist[cur]!=d) continue;
        if (cur==e) return d;
        //cout<<"cur: "<<cur<<" D="<<d<<" SZ="<<g[cur].size()<<endl;
        //cout<<"P: "<<back[cur].x<<" "<<back[cur].y<<endl;
        for(auto nei:g[cur]){
            if (dist[nei.x]>d + nei.y){
                dist[nei.x] = d + nei.y;
                q.push({-dist[nei.x], nei.x});
            }
        }
    }
	return -1;
}
/*
clear
g++ grader.cpp walk2.cpp -o a ; ./a
7 7
0 8
3 7
5 9
7 7
10 6
12 6
14 9
0 1 1
0 2 6
0 6 8
2 3 1
2 6 7
3 4 2
4 6 5
1 5


*/
# 결과 실행 시간 메모리 Grader output
1 Correct 36 ms 47224 KB Output is correct
2 Correct 36 ms 47232 KB Output is correct
3 Correct 36 ms 47224 KB Output is correct
4 Correct 37 ms 47224 KB Output is correct
5 Correct 37 ms 47352 KB Output is correct
6 Correct 37 ms 47360 KB Output is correct
7 Correct 37 ms 47360 KB Output is correct
8 Correct 37 ms 47416 KB Output is correct
9 Correct 37 ms 47336 KB Output is correct
10 Correct 38 ms 47480 KB Output is correct
11 Correct 37 ms 47352 KB Output is correct
12 Correct 37 ms 47360 KB Output is correct
13 Correct 37 ms 47352 KB Output is correct
14 Correct 37 ms 47480 KB Output is correct
15 Correct 37 ms 47224 KB Output is correct
16 Correct 36 ms 47352 KB Output is correct
17 Correct 37 ms 47488 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 36 ms 47232 KB Output is correct
2 Correct 38 ms 47360 KB Output is correct
3 Correct 1512 ms 209676 KB Output is correct
4 Correct 1515 ms 220280 KB Output is correct
5 Correct 1157 ms 197744 KB Output is correct
6 Correct 1022 ms 180728 KB Output is correct
7 Correct 1150 ms 198008 KB Output is correct
8 Correct 1992 ms 253816 KB Output is correct
9 Correct 1270 ms 197368 KB Output is correct
10 Correct 2183 ms 288668 KB Output is correct
11 Correct 796 ms 136184 KB Output is correct
12 Correct 591 ms 112504 KB Output is correct
13 Correct 1837 ms 257716 KB Output is correct
14 Correct 557 ms 109816 KB Output is correct
15 Correct 640 ms 111840 KB Output is correct
16 Correct 587 ms 111608 KB Output is correct
17 Correct 557 ms 109420 KB Output is correct
18 Correct 590 ms 119520 KB Output is correct
19 Correct 49 ms 50424 KB Output is correct
20 Correct 194 ms 78712 KB Output is correct
21 Correct 528 ms 107640 KB Output is correct
22 Correct 525 ms 111608 KB Output is correct
23 Correct 779 ms 122860 KB Output is correct
24 Correct 568 ms 110840 KB Output is correct
25 Correct 558 ms 108664 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 178 ms 65528 KB Output is correct
2 Runtime error 1872 ms 771576 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 178 ms 65528 KB Output is correct
2 Runtime error 1872 ms 771576 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 36 ms 47224 KB Output is correct
2 Correct 36 ms 47232 KB Output is correct
3 Correct 36 ms 47224 KB Output is correct
4 Correct 37 ms 47224 KB Output is correct
5 Correct 37 ms 47352 KB Output is correct
6 Correct 37 ms 47360 KB Output is correct
7 Correct 37 ms 47360 KB Output is correct
8 Correct 37 ms 47416 KB Output is correct
9 Correct 37 ms 47336 KB Output is correct
10 Correct 38 ms 47480 KB Output is correct
11 Correct 37 ms 47352 KB Output is correct
12 Correct 37 ms 47360 KB Output is correct
13 Correct 37 ms 47352 KB Output is correct
14 Correct 37 ms 47480 KB Output is correct
15 Correct 37 ms 47224 KB Output is correct
16 Correct 36 ms 47352 KB Output is correct
17 Correct 37 ms 47488 KB Output is correct
18 Correct 36 ms 47232 KB Output is correct
19 Correct 38 ms 47360 KB Output is correct
20 Correct 1512 ms 209676 KB Output is correct
21 Correct 1515 ms 220280 KB Output is correct
22 Correct 1157 ms 197744 KB Output is correct
23 Correct 1022 ms 180728 KB Output is correct
24 Correct 1150 ms 198008 KB Output is correct
25 Correct 1992 ms 253816 KB Output is correct
26 Correct 1270 ms 197368 KB Output is correct
27 Correct 2183 ms 288668 KB Output is correct
28 Correct 796 ms 136184 KB Output is correct
29 Correct 591 ms 112504 KB Output is correct
30 Correct 1837 ms 257716 KB Output is correct
31 Correct 557 ms 109816 KB Output is correct
32 Correct 640 ms 111840 KB Output is correct
33 Correct 587 ms 111608 KB Output is correct
34 Correct 557 ms 109420 KB Output is correct
35 Correct 590 ms 119520 KB Output is correct
36 Correct 49 ms 50424 KB Output is correct
37 Correct 194 ms 78712 KB Output is correct
38 Correct 528 ms 107640 KB Output is correct
39 Correct 525 ms 111608 KB Output is correct
40 Correct 779 ms 122860 KB Output is correct
41 Correct 568 ms 110840 KB Output is correct
42 Correct 558 ms 108664 KB Output is correct
43 Correct 178 ms 65528 KB Output is correct
44 Runtime error 1872 ms 771576 KB Execution killed with signal 11
45 Halted 0 ms 0 KB -