Submission #899835

# Submission time Handle Problem Language Result Execution time Memory
899835 2024-01-07T07:02:25 Z rxlfd314 Sky Walking (IOI19_walk) C++17
10 / 100
4000 ms 1048576 KB
#include "walk.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ari2 = array<int, 2>;
using arl3 = array<ll, 3>;

#define vt vector
#define size(x) (int((x).size()))
#define all(x) begin(x), end(x)

#define REP(a, b, c, d) for (int a = (b); (d) > 0 ? a <= (c) : a >= (c); a += (d))
#define FOR(a, b, c) REP(a, b, c, 1)
#define ROF(a, b, c) REP(a, b, c, -1)

ll ST12(vt<int> X, vt<int> H, vt<int> L, vt<int> R, vt<int> Y, int S, int G) {
  const int N = size(X), M = size(L);
  map<ari2, vt<ari2>> adj;
  vt<int> ys[N];
  FOR(i, 0, M-1) {
    ys[L[i]].push_back(Y[i]);
    FOR(j, L[i]+1, R[i]) {
      adj[{X[j], Y[i]}].push_back({X[j-1], Y[i]});
      adj[{X[j-1], Y[i]}].push_back({X[j], Y[i]});
      ys[j].push_back(Y[i]);
    }
  }
  FOR(i, 0, N-1) {
    ys[i].push_back(0);
    sort(all(ys[i]));
    ys[i].erase(unique(all(ys[i])), end(ys[i]));
    FOR(j, 1, size(ys[i])-1) {
      if (ys[i][j] > H[i])
        break;
      adj[{X[i], ys[i][j]}].push_back({X[i], ys[i][j-1]});
      adj[{X[i], ys[i][j-1]}].push_back({X[i], ys[i][j]});
    }
  }
  map<ari2, ll> dst;
  priority_queue<arl3, vt<arl3>, greater<arl3>> pq;
  pq.push({dst[{X[S], 0}] = 0, X[S], 0});
  while (size(pq)) {
    auto [d, x, y] = pq.top();
    pq.pop();
    if (d > dst[{x, y}])
      continue;
    #ifdef DEBUG
    cout << "at " << x << ' ' << y << " with dist of " << d << '\n';
    #endif
    for (auto &[a, b] : adj[{x, y}])
      if (dst.find({a, b}) == end(dst) || d + abs(x - a) + abs(y - b) < dst[{a, b}])
        pq.push({dst[{a, b}] = d + abs(x - a) + abs(y - b), a, b});
  }
  return dst.find({X[G], 0}) == end(dst) ? -1 : dst[{X[G], 0}];
}

ll min_distance(vt<int> X, vt<int> H, vt<int> L, vt<int> R, vt<int> Y, int S, int G) {
	const int N = size(X), M = size(L);
  bool sub2 = true;
  FOR(i, 0, M-1)
    sub2 &= R[i] - L[i] < 15;
  if (sub2 || N < 51 && M < 51)
    return ST12(X, H, L, R, Y, S, G);
}

Compilation message

walk.cpp: In function 'll ST12(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>, int, int)':
walk.cpp:45:18: warning: narrowing conversion of 'x' from 'std::tuple_element<1, std::array<long long int, 3> >::type' {aka 'long long int'} to 'int' [-Wnarrowing]
   45 |     if (d > dst[{x, y}])
      |                  ^
walk.cpp:45:21: warning: narrowing conversion of 'y' from 'std::tuple_element<2, std::array<long long int, 3> >::type' {aka 'long long int'} to 'int' [-Wnarrowing]
   45 |     if (d > dst[{x, y}])
      |                     ^
walk.cpp:50:30: warning: narrowing conversion of 'x' from 'std::tuple_element<1, std::array<long long int, 3> >::type' {aka 'long long int'} to 'int' [-Wnarrowing]
   50 |     for (auto &[a, b] : adj[{x, y}])
      |                              ^
walk.cpp:50:33: warning: narrowing conversion of 'y' from 'std::tuple_element<2, std::array<long long int, 3> >::type' {aka 'long long int'} to 'int' [-Wnarrowing]
   50 |     for (auto &[a, b] : adj[{x, y}])
      |                                 ^
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:62:22: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   62 |   if (sub2 || N < 51 && M < 51)
      |               ~~~~~~~^~~~~~~~~
walk.cpp:64:1: warning: control reaches end of non-void function [-Wreturn-type]
   64 | }
      | ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 408 KB Output is correct
10 Correct 2 ms 604 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 432 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 2 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 2659 ms 178836 KB Output is correct
4 Correct 1808 ms 198952 KB Output is correct
5 Runtime error 3894 ms 1048576 KB Execution killed with signal 9
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 109 ms 17804 KB Output is correct
2 Execution timed out 4054 ms 610676 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 109 ms 17804 KB Output is correct
2 Execution timed out 4054 ms 610676 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 408 KB Output is correct
10 Correct 2 ms 604 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 432 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 2 ms 604 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 2659 ms 178836 KB Output is correct
21 Correct 1808 ms 198952 KB Output is correct
22 Runtime error 3894 ms 1048576 KB Execution killed with signal 9
23 Halted 0 ms 0 KB -