Submission #443126

# Submission time Handle Problem Language Result Execution time Memory
443126 2021-07-09T18:38:45 Z peijar Stations (IOI20_stations) C++17
76 / 100
1035 ms 824 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 c[i];
    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 3 ms 408 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 5 ms 384 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 733 ms 608 KB Output is correct
2 Correct 522 ms 600 KB Output is correct
3 Correct 1035 ms 488 KB Output is correct
4 Correct 763 ms 532 KB Output is correct
5 Correct 635 ms 400 KB Output is correct
6 Correct 516 ms 616 KB Output is correct
7 Correct 525 ms 528 KB Output is correct
8 Correct 3 ms 468 KB Output is correct
9 Correct 5 ms 476 KB Output is correct
10 Correct 0 ms 480 KB Output is correct
11 Correct 650 ms 484 KB Output is correct
12 Correct 565 ms 736 KB Output is correct
13 Correct 464 ms 724 KB Output is correct
14 Correct 512 ms 528 KB Output is correct
15 Correct 71 ms 420 KB Output is correct
16 Correct 64 ms 548 KB Output is correct
17 Correct 95 ms 528 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 974 ms 480 KB Output is correct
2 Correct 779 ms 400 KB Output is correct
3 Correct 785 ms 400 KB Output is correct
4 Correct 2 ms 472 KB Output is correct
5 Correct 5 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 752 ms 400 KB Output is correct
8 Correct 869 ms 400 KB Output is correct
9 Correct 642 ms 404 KB Output is correct
10 Correct 762 ms 404 KB Output is correct
11 Correct 6 ms 476 KB Output is correct
12 Correct 4 ms 480 KB Output is correct
13 Correct 5 ms 468 KB Output is correct
14 Correct 4 ms 472 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 602 ms 488 KB Output is correct
17 Correct 538 ms 488 KB Output is correct
18 Correct 618 ms 400 KB Output is correct
19 Correct 607 ms 400 KB Output is correct
20 Correct 558 ms 400 KB Output is correct
# Verdict Execution time Memory Grader output
1 Partially correct 583 ms 676 KB Partially correct
2 Partially correct 588 ms 640 KB Partially correct
3 Correct 976 ms 400 KB Output is correct
4 Correct 710 ms 484 KB Output is correct
5 Correct 714 ms 400 KB Output is correct
6 Partially correct 496 ms 644 KB Partially correct
7 Partially correct 601 ms 488 KB Partially correct
8 Correct 2 ms 476 KB Output is correct
9 Correct 5 ms 480 KB Output is correct
10 Correct 2 ms 468 KB Output is correct
11 Partially correct 538 ms 528 KB Partially correct
12 Partially correct 628 ms 488 KB Partially correct
13 Correct 966 ms 400 KB Output is correct
14 Correct 757 ms 492 KB Output is correct
15 Correct 590 ms 416 KB Output is correct
16 Partially correct 497 ms 656 KB Partially correct
17 Correct 682 ms 488 KB Output is correct
18 Partially correct 489 ms 624 KB Partially correct
19 Partially correct 599 ms 684 KB Partially correct
20 Partially correct 488 ms 528 KB Partially correct
21 Correct 55 ms 472 KB Output is correct
22 Partially correct 85 ms 528 KB Partially correct
23 Partially correct 133 ms 532 KB Partially correct
24 Correct 6 ms 476 KB Output is correct
25 Correct 7 ms 468 KB Output is correct
26 Correct 5 ms 468 KB Output is correct
27 Correct 3 ms 468 KB Output is correct
28 Correct 1 ms 476 KB Output is correct
29 Correct 604 ms 484 KB Output is correct
30 Correct 588 ms 404 KB Output is correct
31 Correct 545 ms 488 KB Output is correct
32 Correct 578 ms 428 KB Output is correct
33 Correct 605 ms 400 KB Output is correct
34 Partially correct 396 ms 632 KB Partially correct
35 Partially correct 476 ms 732 KB Partially correct
36 Partially correct 443 ms 716 KB Partially correct
37 Partially correct 508 ms 696 KB Partially correct
38 Partially correct 598 ms 660 KB Partially correct
39 Partially correct 495 ms 824 KB Partially correct
40 Partially correct 477 ms 708 KB Partially correct
41 Partially correct 502 ms 736 KB Partially correct
42 Partially correct 55 ms 656 KB Partially correct
43 Partially correct 134 ms 528 KB Partially correct
44 Partially correct 156 ms 656 KB Partially correct
45 Partially correct 193 ms 528 KB Partially correct
46 Partially correct 352 ms 556 KB Partially correct
47 Partially correct 324 ms 608 KB Partially correct
48 Partially correct 79 ms 628 KB Partially correct
49 Partially correct 55 ms 768 KB Partially correct