답안 #372998

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
372998 2021-03-03T00:31:18 Z Kanon 기지국 (IOI20_stations) C++14
100 / 100
1037 ms 1168 KB
#include "stations.h"
#include <bits/stdc++.h>

using namespace std;

vector<int> label(int n, int k, vector<int> u, vector<int> v) {
  vector<vector<int>> g(n);
  for(int i = 0; i < n - 1; i++) {
    int a = u[i], b = v[i];
    g[a].push_back(b);
    g[b].push_back(a);
  }
  vector<int> ret(n, -1);
  vector<int> sub(n);
  vector<int> par(n);
  function<void(int, int)> dfs = [&](int v, int p) {
    par[v] = p;
    sub[v] = 1;
    for(int i : g[v]) {
      if(i == p) continue;
      dfs(i, v);
      sub[v] += sub[i];
    }
  };
  dfs(0, -1);
  function<void(int, int, int, bool)> solve = [&](int v, int L, int R, bool head) {
    ret[v] = head ? L : R;
    int st = L + head;
    for(int i : g[v]) {
      if(i == par[v]) continue;
      solve(i, st, st + sub[i] - 1, !head);
      st += sub[i];
    }
  };
  solve(0, 0, n - 1, true);
  return ret;
}

int find_next_station(int s, int t, vector<int> c) {
  if(c.size() == 1) return c[0];
  int n = c.size();
  int par = -1;
  for(int i : c) if(par == -1 || abs(s - i) > abs(s - par)) par = i;
  for(int i = 0; i < n; i++) if(c[i] == par) {
    c.erase(c.begin() + i);
    break;
  }
  c.push_back(s);
  sort(c.begin(), c.end());
  int beg = c[0], fin = c[n - 1];
  if(t < beg || t > fin) return par;
  if(beg == s) {
    return *lower_bound(c.begin(), c.end(), t);
  } else {
    return *prev(upper_bound(c.begin(), c.end(), t));
  }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 634 ms 944 KB Output is correct
2 Correct 499 ms 884 KB Output is correct
3 Correct 942 ms 648 KB Output is correct
4 Correct 747 ms 756 KB Output is correct
5 Correct 586 ms 1060 KB Output is correct
6 Correct 439 ms 948 KB Output is correct
7 Correct 555 ms 884 KB Output is correct
8 Correct 3 ms 996 KB Output is correct
9 Correct 5 ms 736 KB Output is correct
10 Correct 2 ms 736 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 524 ms 928 KB Output is correct
2 Correct 485 ms 756 KB Output is correct
3 Correct 1037 ms 756 KB Output is correct
4 Correct 676 ms 868 KB Output is correct
5 Correct 706 ms 756 KB Output is correct
6 Correct 527 ms 756 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 519 ms 884 KB Output is correct
2 Correct 486 ms 1024 KB Output is correct
3 Correct 980 ms 868 KB Output is correct
4 Correct 702 ms 736 KB Output is correct
5 Correct 690 ms 876 KB Output is correct
6 Correct 585 ms 884 KB Output is correct
7 Correct 564 ms 884 KB Output is correct
8 Correct 3 ms 876 KB Output is correct
9 Correct 4 ms 736 KB Output is correct
10 Correct 2 ms 756 KB Output is correct
11 Correct 692 ms 756 KB Output is correct
12 Correct 555 ms 1120 KB Output is correct
13 Correct 531 ms 992 KB Output is correct
14 Correct 489 ms 1024 KB Output is correct
15 Correct 54 ms 860 KB Output is correct
16 Correct 83 ms 944 KB Output is correct
17 Correct 113 ms 776 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1022 ms 868 KB Output is correct
2 Correct 785 ms 996 KB Output is correct
3 Correct 594 ms 736 KB Output is correct
4 Correct 2 ms 756 KB Output is correct
5 Correct 5 ms 736 KB Output is correct
6 Correct 2 ms 756 KB Output is correct
7 Correct 657 ms 884 KB Output is correct
8 Correct 958 ms 736 KB Output is correct
9 Correct 754 ms 868 KB Output is correct
10 Correct 602 ms 736 KB Output is correct
11 Correct 5 ms 916 KB Output is correct
12 Correct 7 ms 776 KB Output is correct
13 Correct 6 ms 736 KB Output is correct
14 Correct 4 ms 756 KB Output is correct
15 Correct 2 ms 756 KB Output is correct
16 Correct 653 ms 868 KB Output is correct
17 Correct 545 ms 996 KB Output is correct
18 Correct 530 ms 884 KB Output is correct
19 Correct 511 ms 736 KB Output is correct
20 Correct 505 ms 868 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 573 ms 876 KB Output is correct
2 Correct 484 ms 864 KB Output is correct
3 Correct 904 ms 868 KB Output is correct
4 Correct 771 ms 884 KB Output is correct
5 Correct 640 ms 736 KB Output is correct
6 Correct 494 ms 884 KB Output is correct
7 Correct 461 ms 1024 KB Output is correct
8 Correct 3 ms 756 KB Output is correct
9 Correct 6 ms 868 KB Output is correct
10 Correct 2 ms 736 KB Output is correct
11 Correct 533 ms 912 KB Output is correct
12 Correct 589 ms 776 KB Output is correct
13 Correct 1006 ms 756 KB Output is correct
14 Correct 857 ms 736 KB Output is correct
15 Correct 704 ms 892 KB Output is correct
16 Correct 453 ms 788 KB Output is correct
17 Correct 744 ms 1012 KB Output is correct
18 Correct 530 ms 968 KB Output is correct
19 Correct 547 ms 940 KB Output is correct
20 Correct 487 ms 756 KB Output is correct
21 Correct 57 ms 736 KB Output is correct
22 Correct 101 ms 756 KB Output is correct
23 Correct 115 ms 756 KB Output is correct
24 Correct 5 ms 756 KB Output is correct
25 Correct 6 ms 756 KB Output is correct
26 Correct 6 ms 756 KB Output is correct
27 Correct 5 ms 876 KB Output is correct
28 Correct 2 ms 736 KB Output is correct
29 Correct 621 ms 756 KB Output is correct
30 Correct 596 ms 736 KB Output is correct
31 Correct 666 ms 1060 KB Output is correct
32 Correct 602 ms 756 KB Output is correct
33 Correct 546 ms 756 KB Output is correct
34 Correct 426 ms 884 KB Output is correct
35 Correct 559 ms 924 KB Output is correct
36 Correct 560 ms 1168 KB Output is correct
37 Correct 462 ms 1140 KB Output is correct
38 Correct 512 ms 864 KB Output is correct
39 Correct 410 ms 1108 KB Output is correct
40 Correct 498 ms 1120 KB Output is correct
41 Correct 569 ms 1108 KB Output is correct
42 Correct 69 ms 840 KB Output is correct
43 Correct 132 ms 736 KB Output is correct
44 Correct 144 ms 736 KB Output is correct
45 Correct 178 ms 980 KB Output is correct
46 Correct 393 ms 776 KB Output is correct
47 Correct 327 ms 1000 KB Output is correct
48 Correct 61 ms 756 KB Output is correct
49 Correct 63 ms 876 KB Output is correct