Submission #443124

# Submission time Handle Problem Language Result Execution time Memory
443124 2021-07-09T18:34:51 Z peijar Stations (IOI20_stations) C++17
10 / 100
1057 ms 764 KB
#include "stations.h"
#include <bits/stdc++.h>
#include <vector>
using namespace std;

vector<vector<int>> adj;
vector<int> tin, tout;
vector<int> depth;
int curTime;

void dfs(int u, int p) {
  tin[u] = curTime++;
  for (int v : adj[u])
    if (v != p) {
      depth[v] = depth[u] + 1;
      dfs(v, u);
    }
  tout[u] = curTime++;
}

vector<int> label(int n, int k, vector<int> u, vector<int> v) {
  curTime = 0;
  tin.clear();
  tout.clear();
  depth.clear();
  adj.clear();
  tin.resize(n), tout.resize(n), adj.resize(n), depth.resize(n);
  for (int i = 0; i < n - 1; ++i) {
    adj[u[i]].push_back(v[i]);
    adj[v[i]].push_back(u[i]);
  }
  dfs(0, 0);
  vector<int> labels(n);
  for (int i = 0; i < n; i++)
    labels[i] = depth[i] % 2 ? tout[i] : tin[i];

  for (int x : labels)
    cerr << x << ' ';
  cerr << endl;
  return labels;
}

int find_next_station(int s, int t, vector<int> c) {
  if (!s) {
    for (int i = 0; i < (int)c.size(); ++i)
      if (t <= c[i])
        return c[i];
  }
  if (c.size() == 1)
    return c[0];
  for (auto v : c)
    if (v == t)
      return v;

  bool allGreater = true, allLess = true;
  for (int i : c)
    allGreater &= i > s, allLess &= i < s;

  if (allGreater) { // s is tin, all others are tout
    int p = c.back();
    c.pop_back();
    if (t < c[0] and t > s)
      return c[0];
    for (int i = 1; i < (int)c.size(); ++i)
      if (t < c[i] and t > c[i - 1])
        return t;
    return p;
  } else { // s is tout and all others are tin
    int p = c.front();
    c.erase(c.begin());
    if (t > c.back() and t < s)
      return c.back();
    for (int i = 0; i + 1 < (int)c.size(); ++i)
      if (t > c[i] and t < c[i + 1])
        return c[i];
    return p;
  }
}
# Verdict Execution time Memory Grader output
1 Incorrect 18 ms 468 KB Invalid labels (values out of range). scenario=2, k=1000, vertex=1, label=1990
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 35 ms 412 KB Invalid labels (values out of range). scenario=0, k=1000, vertex=1, label=1022
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 584 ms 764 KB Output is correct
2 Correct 531 ms 636 KB Output is correct
3 Correct 1057 ms 400 KB Output is correct
4 Correct 687 ms 480 KB Output is correct
5 Correct 585 ms 488 KB Output is correct
6 Correct 524 ms 612 KB Output is correct
7 Correct 547 ms 528 KB Output is correct
8 Correct 3 ms 456 KB Output is correct
9 Correct 5 ms 480 KB Output is correct
10 Correct 2 ms 468 KB Output is correct
11 Correct 714 ms 488 KB Output is correct
12 Incorrect 553 ms 680 KB Wrong query response.
13 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1012 ms 400 KB Output is correct
2 Correct 880 ms 400 KB Output is correct
3 Correct 692 ms 400 KB Output is correct
4 Correct 2 ms 468 KB Output is correct
5 Correct 6 ms 468 KB Output is correct
6 Correct 2 ms 468 KB Output is correct
7 Correct 764 ms 488 KB Output is correct
8 Correct 999 ms 400 KB Output is correct
9 Correct 793 ms 400 KB Output is correct
10 Correct 651 ms 528 KB Output is correct
11 Correct 7 ms 448 KB Output is correct
12 Correct 7 ms 468 KB Output is correct
13 Correct 5 ms 476 KB Output is correct
14 Correct 4 ms 468 KB Output is correct
15 Correct 2 ms 468 KB Output is correct
16 Correct 585 ms 400 KB Output is correct
17 Correct 599 ms 400 KB Output is correct
18 Correct 539 ms 528 KB Output is correct
19 Correct 545 ms 400 KB Output is correct
20 Correct 572 ms 400 KB Output is correct
# Verdict Execution time Memory Grader output
1 Partially correct 639 ms 648 KB Partially correct
2 Partially correct 520 ms 652 KB Partially correct
3 Correct 992 ms 520 KB Output is correct
4 Correct 765 ms 528 KB Output is correct
5 Correct 716 ms 400 KB Output is correct
6 Partially correct 572 ms 664 KB Partially correct
7 Partially correct 509 ms 616 KB Partially correct
8 Correct 3 ms 468 KB Output is correct
9 Correct 5 ms 468 KB Output is correct
10 Correct 2 ms 468 KB Output is correct
11 Incorrect 526 ms 596 KB Wrong query response.
12 Halted 0 ms 0 KB -