답안 #418124

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
418124 2021-06-05T06:32:38 Z usachevd0 Sky Walking (IOI19_walk) C++14
10 / 100
4000 ms 836756 KB
#include <bits/stdc++.h>
#ifndef LOCAL
    #include "walk.h"
#endif

using namespace std;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define Time (clock() * 1.0 / CLOCKS_PER_SEC)
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
using ld = long double;
template<typename T1, typename T2> bool chkmin(T1& x, T2 y) {
    return y < x ? (x = y, true) : false;
}
template<typename T1, typename T2> bool chkmax(T1& x, T2 y) {
    return y > x ? (x = y, true) : false;
}
void debug_out() {
    cerr << endl;
}
template<typename T1, typename... T2> void debug_out(T1 A, T2... B) {
    cerr << ' ' << A;
    debug_out(B...);
}
template<typename T> void mdebug_out(T* a, int n) {
    for (int i = 0; i < n; ++i)
        cerr << a[i] << ' ';
    cerr << endl;
}
#ifdef LOCAL
    #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
    #define mdebug(a, n) cerr << #a << ": ", mdebug_out(a, n)
#else
    #define debug(...) 1337
    #define mdebug(a, n) 1337
#endif
template<typename T> ostream& operator << (ostream& stream, const vector<T>& v) {
    for (auto& x : v)
        stream << x << ' ';
    return stream;
}
template<typename T1, typename T2> ostream& operator << (ostream& stream, const pair<T1, T2>& p) {
    return stream << p.first << ' ' << p.second;
}

const ll INF64 = 1e18;
const int maxN = 100005;
int n, m;

const int maxV = 4e6 + 6;
int V;
vector<pii> G[maxV];
ll dist[maxV];
multiset<pli> pq;

map<int, int> ptIdx[maxN];
int getIdx(int x, int y) {
    if (ptIdx[x].count(y))
        return ptIdx[x][y];
    // debug(x, y, V);
    return ptIdx[x][y] = V++;
}

void addEdge(int u, int v, int w) {
    // debug(u, v, w);
    G[u].emplace_back(v, w);
    G[v].emplace_back(u, w);
}

ll min_distance(vector<int> X, vector<int> H, vector<int> L, vector<int> R, vector<int> Y, int SI, int TI) {
    n = X.size(), m = L.size();
    
    int S, T;
    for (int i = 0; i < n; ++i) {
        int v = getIdx(i, 0);
        if (i == SI)
            S = v;
        if (i == TI)
            T = v;
    }
    // debug(S, T);
    for (int j = 0; j < m; ++j) {
        int l = L[j], r = R[j], y = Y[j];
        int last_i = l, last_v = getIdx(l, y);
        for (int i = l + 1; i <= r; ++i) {
            if (H[i] >= y) {
                int v = getIdx(i, y);
                addEdge(last_v, v, X[i] - X[last_i]);
                last_v = v;
                last_i = i;
            }
        }
    }
    for (int i = 0; i < n; ++i) {
        int last_y = -1, last_v = -1;
        for (auto& [y, v] : ptIdx[i]) {
            if (last_y != -1) {
                addEdge(last_v, v, y - last_y);
            }
            last_y = y;
            last_v = v;
        }
    }
    
    fill(dist, dist + V, INF64);
    dist[S] = 0;
    pq.insert({0, S});
    while (!pq.empty()) {
        ll _d = pq.begin()->fi;
        int v = pq.begin()->se;
        pq.erase(pq.begin());
        if (_d != dist[v]) continue;
        // debug(v, dist[v]);
        if (v == T) return dist[v];
        for (auto& [u, w] : G[v])
            if (chkmin(dist[u], dist[v] + w))
                pq.insert({dist[u], u});
    }
    return -1;
}


#ifdef LOCAL

int32_t main() {
#ifdef LOCAL
    freopen("in", "r", stdin);
#endif
    ios::sync_with_stdio(0);
    cin.tie(0);
    
        int n, m;
    assert(2 == scanf("%d%d", &n, &m));
    vector<int> x(n), h(n);
    for (int i = 0; i < n; i++)
        assert(2 == scanf("%d%d", &x[i], &h[i]));
    vector<int> l(m), r(m), y(m);
    for (int i = 0; i < m; i++)
        assert(3 == scanf("%d%d%d", &l[i], &r[i], &y[i]));
    int s, g;
    assert(2 == scanf("%d%d", &s, &g));
    fclose(stdin);

    long long result = min_distance(x, h, l, r, y, s, g);

    printf("%lld\n", result);
    fclose(stdout);
    
    return 0;
}

#endif

Compilation message

walk.cpp: In function 'll min_distance(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>, int, int)':
walk.cpp:105:20: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
  105 |         for (auto& [y, v] : ptIdx[i]) {
      |                    ^
walk.cpp:124:20: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
  124 |         for (auto& [u, w] : G[v])
      |                    ^
walk.cpp:123:9: warning: 'T' may be used uninitialized in this function [-Wmaybe-uninitialized]
  123 |         if (v == T) return dist[v];
      |         ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 52 ms 98884 KB Output is correct
2 Correct 51 ms 98876 KB Output is correct
3 Correct 50 ms 98872 KB Output is correct
4 Correct 51 ms 98828 KB Output is correct
5 Correct 51 ms 98884 KB Output is correct
6 Correct 53 ms 98972 KB Output is correct
7 Correct 52 ms 98968 KB Output is correct
8 Correct 53 ms 98988 KB Output is correct
9 Correct 52 ms 98916 KB Output is correct
10 Correct 54 ms 99012 KB Output is correct
11 Correct 51 ms 98904 KB Output is correct
12 Correct 53 ms 98900 KB Output is correct
13 Correct 52 ms 98836 KB Output is correct
14 Correct 52 ms 98876 KB Output is correct
15 Correct 52 ms 98884 KB Output is correct
16 Correct 57 ms 98996 KB Output is correct
17 Correct 53 ms 98940 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 51 ms 98832 KB Output is correct
2 Correct 54 ms 98892 KB Output is correct
3 Correct 732 ms 190840 KB Output is correct
4 Correct 821 ms 202976 KB Output is correct
5 Correct 518 ms 188836 KB Output is correct
6 Correct 1010 ms 178248 KB Output is correct
7 Correct 515 ms 188908 KB Output is correct
8 Correct 1010 ms 219636 KB Output is correct
9 Correct 628 ms 187588 KB Output is correct
10 Correct 1145 ms 243140 KB Output is correct
11 Correct 431 ms 149996 KB Output is correct
12 Correct 326 ms 134164 KB Output is correct
13 Correct 1008 ms 225204 KB Output is correct
14 Correct 2935 ms 132796 KB Output is correct
15 Correct 1668 ms 133508 KB Output is correct
16 Correct 400 ms 134728 KB Output is correct
17 Correct 397 ms 132904 KB Output is correct
18 Execution timed out 4096 ms 115924 KB Time limit exceeded
19 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 121 ms 108060 KB Output is correct
2 Runtime error 2716 ms 836756 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 121 ms 108060 KB Output is correct
2 Runtime error 2716 ms 836756 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 52 ms 98884 KB Output is correct
2 Correct 51 ms 98876 KB Output is correct
3 Correct 50 ms 98872 KB Output is correct
4 Correct 51 ms 98828 KB Output is correct
5 Correct 51 ms 98884 KB Output is correct
6 Correct 53 ms 98972 KB Output is correct
7 Correct 52 ms 98968 KB Output is correct
8 Correct 53 ms 98988 KB Output is correct
9 Correct 52 ms 98916 KB Output is correct
10 Correct 54 ms 99012 KB Output is correct
11 Correct 51 ms 98904 KB Output is correct
12 Correct 53 ms 98900 KB Output is correct
13 Correct 52 ms 98836 KB Output is correct
14 Correct 52 ms 98876 KB Output is correct
15 Correct 52 ms 98884 KB Output is correct
16 Correct 57 ms 98996 KB Output is correct
17 Correct 53 ms 98940 KB Output is correct
18 Correct 51 ms 98832 KB Output is correct
19 Correct 54 ms 98892 KB Output is correct
20 Correct 732 ms 190840 KB Output is correct
21 Correct 821 ms 202976 KB Output is correct
22 Correct 518 ms 188836 KB Output is correct
23 Correct 1010 ms 178248 KB Output is correct
24 Correct 515 ms 188908 KB Output is correct
25 Correct 1010 ms 219636 KB Output is correct
26 Correct 628 ms 187588 KB Output is correct
27 Correct 1145 ms 243140 KB Output is correct
28 Correct 431 ms 149996 KB Output is correct
29 Correct 326 ms 134164 KB Output is correct
30 Correct 1008 ms 225204 KB Output is correct
31 Correct 2935 ms 132796 KB Output is correct
32 Correct 1668 ms 133508 KB Output is correct
33 Correct 400 ms 134728 KB Output is correct
34 Correct 397 ms 132904 KB Output is correct
35 Execution timed out 4096 ms 115924 KB Time limit exceeded
36 Halted 0 ms 0 KB -