답안 #657331

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
657331 2022-11-09T14:34:41 Z evenvalue Sky Walking (IOI19_walk) C++17
10 / 100
4000 ms 1048576 KB
#include "walk.h"
#include <bits/stdc++.h>
using namespace std;

template<typename T>
using min_heap = priority_queue<T, vector<T>, greater<T>>;
template<typename T>
using max_heap = priority_queue<T, vector<T>, less<T>>;

using int64 = long long;
using ld = long double;

constexpr int kInf = 1e9 + 10;
constexpr int64 kInf64 = 1e15 + 10;
constexpr int kMod = 1e9 + 7;

pair<vector<int64>, vector<int>> dijkstra(const vector<vector<pair<int, int>>> &g, const int s) {
  const int n = (int) g.size();

  vector<int64> d(n, kInf64);
  vector<int> p(n, -1);
  min_heap<pair<int64, int>> q;

  d[s] = 0;
  q.push({0, s});

  while (not q.empty()) {
    const auto [dist, x] = q.top();
    q.pop();
    if (d[x] < dist) continue;
    for (const auto &[y, w] : g[x]) {
      if (d[y] <= d[x] + w) continue;
      d[y] = d[x] + w;
      p[y] = x;
      q.push({d[y], y});
    }
  }

  return make_pair(d, p);
}

struct building {
  int x;
  int h;
};

struct skywalk {
  int i;
  int l;
  int r;
  int h;

  bool operator<(const skywalk &other) const {
    return h < other.h;
  }
};

int64 min_distance(vector<int> X, vector<int> H, vector<int> L, vector<int> R, vector<int> Y, int S, int G) {
  const int n = (int) X.size();
  const int m = (int) L.size();

  vector<building> buildings(n);
  for (int i = 0; i < n; i++) {
    buildings[i].h = H[i];
    buildings[i].x = X[i];
  }

  vector<skywalk> skywalks(m);
  for (int j = 0; j < m; j++) {
    skywalks[j].i = j;
    skywalks[j].l = L[j];
    skywalks[j].r = R[j];
    skywalks[j].h = Y[j];
  }

  sort(skywalks.begin(), skywalks.end());

  vector<vector<pair<int, int>>> g;
  vector<pair<int, int>> last(n);

  auto add_node = [&]() -> int {
    g.emplace_back();
    return (int) g.size() - 1;
  };

  auto add_edge = [&](const int x, const int y, const int w) {
    g[x].emplace_back(y, w);
    g[y].emplace_back(x, w);
  };

  for (int i = 0; i < n; i++) {
    last[i] = make_pair(add_node(), 0);
  }

  for (skywalk s : skywalks) {
    int prev = s.l;
    for (int i = s.l, x = -1; i <= s.r; i++) {
      if (s.h > buildings[i].h) continue;

      const int y = add_node();
      if (x != -1) add_edge(x, y, buildings[i].x - buildings[prev].x);
      add_edge(y, last[i].first, s.h - last[i].second);
      last[i] = make_pair(y, s.h);
      x = y;
      prev = i;
    }
  }

  const int64 ans = dijkstra(g, S).first[G];
  return (ans == kInf64 ? -1 : ans);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 296 KB Output is correct
3 Correct 1 ms 304 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 300 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 304 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 296 KB Output is correct
3 Correct 355 ms 73176 KB Output is correct
4 Correct 403 ms 84200 KB Output is correct
5 Correct 230 ms 73404 KB Output is correct
6 Correct 524 ms 66144 KB Output is correct
7 Correct 222 ms 73468 KB Output is correct
8 Correct 436 ms 91976 KB Output is correct
9 Correct 253 ms 72456 KB Output is correct
10 Correct 498 ms 112812 KB Output is correct
11 Correct 226 ms 43888 KB Output is correct
12 Correct 184 ms 36348 KB Output is correct
13 Correct 460 ms 99976 KB Output is correct
14 Correct 1748 ms 34888 KB Output is correct
15 Correct 950 ms 35740 KB Output is correct
16 Correct 181 ms 35636 KB Output is correct
17 Correct 176 ms 34324 KB Output is correct
18 Execution timed out 4062 ms 20924 KB Time limit exceeded
19 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 58 ms 14020 KB Output is correct
2 Correct 2090 ms 486324 KB Output is correct
3 Runtime error 2049 ms 1048576 KB Execution killed with signal 9
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 58 ms 14020 KB Output is correct
2 Correct 2090 ms 486324 KB Output is correct
3 Runtime error 2049 ms 1048576 KB Execution killed with signal 9
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 296 KB Output is correct
3 Correct 1 ms 304 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 300 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 304 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 296 KB Output is correct
20 Correct 355 ms 73176 KB Output is correct
21 Correct 403 ms 84200 KB Output is correct
22 Correct 230 ms 73404 KB Output is correct
23 Correct 524 ms 66144 KB Output is correct
24 Correct 222 ms 73468 KB Output is correct
25 Correct 436 ms 91976 KB Output is correct
26 Correct 253 ms 72456 KB Output is correct
27 Correct 498 ms 112812 KB Output is correct
28 Correct 226 ms 43888 KB Output is correct
29 Correct 184 ms 36348 KB Output is correct
30 Correct 460 ms 99976 KB Output is correct
31 Correct 1748 ms 34888 KB Output is correct
32 Correct 950 ms 35740 KB Output is correct
33 Correct 181 ms 35636 KB Output is correct
34 Correct 176 ms 34324 KB Output is correct
35 Execution timed out 4062 ms 20924 KB Time limit exceeded
36 Halted 0 ms 0 KB -