Submission #1077458

# Submission time Handle Problem Language Result Execution time Memory
1077458 2024-08-27T07:26:55 Z juicy Stations (IOI20_stations) C++17
0 / 100
613 ms 1196 KB
#include "stations.h"

#include <bits/stdc++.h>

std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) {
  std::vector<std::vector<int>> g(n);
  for (int i = 0; i < n - 1; ++i) {
    g[u[i]].push_back(v[i]);
    g[v[i]].push_back(u[i]);
  }
  std::vector<int> lab(n), tin(n), tout(n);
  std::function<void(int, int, int)> dfs = [&](int u, int p, int dep) {
    static int timer = 0;
    tin[u] = ++timer;
    for (int v : g[u]) {
      if (v ^ p) {
        dfs(v, u, dep + 1);
      }
    }
    tout[u] = ++timer;
    lab[u] = dep & 1 ? tout[u] : tin[u];
  };
  dfs(0, 0, 0);
  std::vector<int> ord(n); iota(ord.begin(), ord.end(), 0);
  std::sort(ord.begin(), ord.end(), [&](int u, int v) {
    return lab[u] < lab[v];
  });
  for (int i = 0; i < n; ++i) {
    lab[ord[i]] = i;
  }
  return lab;
}

std::array<int, 3> qry(int u, std::vector<int> &c) {
  if (c.size() == 1) {
    return {c[0], u, u};
  }
  if (u <= c[0]) {
    int pr = c.back(); c.pop_back();
    return {pr, u, c.back()};
  }
  int pr = c[0]; c.erase(c.begin());
  return {pr, c[0], u};
}

int find_next_station(int s, int t, std::vector<int> c) {
  auto [pr, l, r] = qry(s, c);
  if (l <= t && t <= r) {
    bool f = pr < s;
    int lst = -1;
    for (int x : c) {
      if (!f && x > t) {
        assert(~lst);
        return lst;
      }
      if (f && t <= x) {
        return x;
      }
      lst = x;
    }
  } 
  return pr;
}
# Verdict Execution time Memory Grader output
1 Runtime error 3 ms 940 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 4 ms 940 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 3 ms 1196 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 613 ms 684 KB Output is correct
2 Incorrect 455 ms 684 KB Wrong query response.
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 3 ms 940 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -