답안 #424014

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
424014 2021-06-11T15:22:44 Z yuto1115 Sky Walking (IOI19_walk) C++17
24 / 100
4000 ms 660936 KB
#include "walk.h"
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define rep2(i, s, n) for(ll i = ll(s); i < ll(n); i++)
#define rrep(i, n) for(ll i = ll(n)-1; i >= 0; i--)
#define pb push_back
#define eb emplace_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vp = vector<P>;
using vvp = vector<vp>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vs = vector<string>;

const int inf = 1001001001;
const ll linf = 1001001001001001001;

template<class T>
bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

ll min_distance(vi x, vi h, vi l, vi r, vi y, int s, int g) {
    int n = x.size();
    int m = l.size();
    vp pos;
    pos.eb(s, 0);
    pos.eb(g, 0);
    vi ob(n);
    iota(all(ob), 0);
    sort(all(ob), [&](int i, int j) { return h[i] < h[j]; });
    vi oe(m);
    iota(all(oe), 0);
    sort(all(oe), [&](int i, int j) { return y[i] < y[j]; });
    {
        set<int> st;
        rep(i, n) st.insert(i);
        int it = 0;
        for (int i : oe) {
            while (it < n and h[ob[it]] < y[i]) {
                st.erase(ob[it++]);
            }
            int cnt = 0;
            auto now = st.lower_bound(l[i]);
            while (now != st.end() and *now <= r[i]) {
                pos.eb(*now, y[i]);
                now++;
            }
        }
    }
    sort(all(pos));
    pos.erase(unique(all(pos)), pos.end());
    int sz = pos.size();
    map<P, int> id;
    rep(i, sz) id[pos[i]] = i;
    vvp G(sz);
    rep(i, sz - 1) if (pos[i].first == pos[i + 1].first) {
            G[i].eb(i + 1, pos[i + 1].second - pos[i].second);
            G[i + 1].eb(i, pos[i + 1].second - pos[i].second);
        }
    {
        set<int> st;
        rep(i, n) st.insert(i);
        int it = 0;
        for (int i : oe) {
            while (it < n and h[ob[it]] < y[i]) {
                st.erase(ob[it++]);
            }
            auto now = st.lower_bound(l[i]);
            int pre = -1;
            while (now != st.end() and *now <= r[i]) {
                int nx = id[{*now, y[i]}];
                if (pre >= 0) {
                    assert(pos[nx].first >= pos[pre].first);
                    G[pre].eb(nx, x[pos[nx].first] - x[pos[pre].first]);
                    G[nx].eb(pre, x[pos[nx].first] - x[pos[pre].first]);
                }
                pre = nx;
                now++;
            }
        }
    }
    vl dist(sz, linf);
    using lp = pair<ll, int>;
    priority_queue<lp, vector<lp>, greater<lp>> pq;
    dist[id[{s, 0}]] = 0;
    pq.emplace(0, id[{s, 0}]);
    while (!pq.empty()) {
        auto[d, u] = pq.top();
        pq.pop();
        if (dist[u] < d) continue;
        for (auto[v, len] : G[u]) {
            if (chmin(dist[v], d + len)) pq.emplace(d + len, v);
        }
    }
    ll ans = dist[id[{g, 0}]];
    return (ans == linf ? -1 : ans);
}

Compilation message

walk.cpp: In function 'll min_distance(vi, vi, vi, vi, vi, int, int)':
walk.cpp:64:17: warning: unused variable 'cnt' [-Wunused-variable]
   64 |             int cnt = 0;
      |                 ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1591 ms 112156 KB Output is correct
4 Correct 1628 ms 119716 KB Output is correct
5 Correct 1087 ms 101928 KB Output is correct
6 Correct 980 ms 89392 KB Output is correct
7 Correct 1104 ms 102100 KB Output is correct
8 Correct 2142 ms 145068 KB Output is correct
9 Correct 1371 ms 102284 KB Output is correct
10 Correct 2446 ms 165908 KB Output is correct
11 Correct 918 ms 60948 KB Output is correct
12 Correct 682 ms 38692 KB Output is correct
13 Correct 1997 ms 145492 KB Output is correct
14 Correct 421 ms 37640 KB Output is correct
15 Correct 452 ms 38072 KB Output is correct
16 Correct 432 ms 40144 KB Output is correct
17 Correct 461 ms 38556 KB Output is correct
18 Correct 309 ms 41440 KB Output is correct
19 Correct 11 ms 2112 KB Output is correct
20 Correct 130 ms 18612 KB Output is correct
21 Correct 477 ms 38592 KB Output is correct
22 Correct 472 ms 37792 KB Output is correct
23 Correct 361 ms 45816 KB Output is correct
24 Correct 423 ms 39392 KB Output is correct
25 Correct 517 ms 38456 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 139 ms 12096 KB Output is correct
2 Execution timed out 4099 ms 660936 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 139 ms 12096 KB Output is correct
2 Execution timed out 4099 ms 660936 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 1591 ms 112156 KB Output is correct
21 Correct 1628 ms 119716 KB Output is correct
22 Correct 1087 ms 101928 KB Output is correct
23 Correct 980 ms 89392 KB Output is correct
24 Correct 1104 ms 102100 KB Output is correct
25 Correct 2142 ms 145068 KB Output is correct
26 Correct 1371 ms 102284 KB Output is correct
27 Correct 2446 ms 165908 KB Output is correct
28 Correct 918 ms 60948 KB Output is correct
29 Correct 682 ms 38692 KB Output is correct
30 Correct 1997 ms 145492 KB Output is correct
31 Correct 421 ms 37640 KB Output is correct
32 Correct 452 ms 38072 KB Output is correct
33 Correct 432 ms 40144 KB Output is correct
34 Correct 461 ms 38556 KB Output is correct
35 Correct 309 ms 41440 KB Output is correct
36 Correct 11 ms 2112 KB Output is correct
37 Correct 130 ms 18612 KB Output is correct
38 Correct 477 ms 38592 KB Output is correct
39 Correct 472 ms 37792 KB Output is correct
40 Correct 361 ms 45816 KB Output is correct
41 Correct 423 ms 39392 KB Output is correct
42 Correct 517 ms 38456 KB Output is correct
43 Correct 139 ms 12096 KB Output is correct
44 Execution timed out 4099 ms 660936 KB Time limit exceeded
45 Halted 0 ms 0 KB -