답안 #319758

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
319758 2020-11-06T11:26:28 Z spatarel 기지국 (IOI20_stations) C++17
100 / 100
1186 ms 1228 KB
#include "stations.h"
#include <algorithm>
#include <stdio.h>
#include <vector>

const int MAX_N = 1000;

bool visited[MAX_N];
std::vector<int> neighbours[MAX_N];
int counter;

void visit(std::vector<int> &labels, int u) {
  labels[u] = counter;
  //printf("%d->%d\n", u, counter);
  counter++;
}

void dfs(std::vector<int> &labels, int u, bool parity = false) {
  //printf("dfs: %d %d\n", u, parity);
  visited[u] = true;
  if (parity) {
    visit(labels, u);
  }
  for (int v : neighbours[u]) {
    if (!visited[v]) {
      dfs(labels, v, !parity);
    }
  }
  if (!parity) {
    visit(labels, u);
  }
}

std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) {
  std::vector<int> labels(n);
  for (int i = 0; i < n - 1; i++) {
    neighbours[u[i]].push_back(v[i]);
    neighbours[v[i]].push_back(u[i]);
  }
  counter = 0;
  for (int i = 0; i < n; i++) {
    visited[i] = false;
  }
  dfs(labels, 0);
  for (int i = 0; i < n; i++) {
    neighbours[i].clear();
  }
  return labels;
}

int find_next_station(int s, int t, std::vector<int> c) {
  if (c.size() == 1) {
    return c[0];
  }
  int answer;
  std::sort(c.begin(), c.end());
  /*
  for (int n : c) {
    printf("%d ", n);
  }
  printf("\n");//*/
  if (s < c[0]) {
    int p = c.back();
    int l = s;
    int r = c.end()[-2];
    if (l <= t && t <= r) {
      int i = c.size() - 2;
      while (i >= 0 && t <= c[i]) {
        i--;
      }
      answer = c[i + 1];
    } else {
      answer = p;
    }
  } else {
    int p = c[0];
    int l = c[1];
    int r = s;
    //printf("%d %d\n", l, r);
    if (l <= t && t <= r) {
      int i = 1;
      while (i < (int)c.size() && c[i] <= t) {
        i++;
      }
      answer = c[i - 1];
    } else {
      answer = p;
    }
  }
  //printf("%d->%d (%d)\n", s, t, answer);
  return answer;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 524 ms 1136 KB Output is correct
2 Correct 469 ms 876 KB Output is correct
3 Correct 911 ms 756 KB Output is correct
4 Correct 681 ms 848 KB Output is correct
5 Correct 593 ms 756 KB Output is correct
6 Correct 449 ms 988 KB Output is correct
7 Correct 476 ms 1008 KB Output is correct
8 Correct 2 ms 860 KB Output is correct
9 Correct 4 ms 736 KB Output is correct
10 Correct 1 ms 868 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 447 ms 756 KB Output is correct
2 Correct 548 ms 864 KB Output is correct
3 Correct 896 ms 964 KB Output is correct
4 Correct 683 ms 756 KB Output is correct
5 Correct 579 ms 856 KB Output is correct
6 Correct 598 ms 756 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 541 ms 1016 KB Output is correct
2 Correct 454 ms 1100 KB Output is correct
3 Correct 854 ms 756 KB Output is correct
4 Correct 732 ms 860 KB Output is correct
5 Correct 612 ms 736 KB Output is correct
6 Correct 480 ms 992 KB Output is correct
7 Correct 438 ms 884 KB Output is correct
8 Correct 3 ms 860 KB Output is correct
9 Correct 4 ms 756 KB Output is correct
10 Correct 1 ms 860 KB Output is correct
11 Correct 586 ms 992 KB Output is correct
12 Correct 456 ms 1068 KB Output is correct
13 Correct 504 ms 1208 KB Output is correct
14 Correct 422 ms 776 KB Output is correct
15 Correct 54 ms 856 KB Output is correct
16 Correct 65 ms 936 KB Output is correct
17 Correct 116 ms 876 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1033 ms 740 KB Output is correct
2 Correct 839 ms 1012 KB Output is correct
3 Correct 791 ms 860 KB Output is correct
4 Correct 2 ms 844 KB Output is correct
5 Correct 3 ms 756 KB Output is correct
6 Correct 1 ms 756 KB Output is correct
7 Correct 697 ms 756 KB Output is correct
8 Correct 915 ms 856 KB Output is correct
9 Correct 721 ms 736 KB Output is correct
10 Correct 618 ms 876 KB Output is correct
11 Correct 4 ms 964 KB Output is correct
12 Correct 5 ms 900 KB Output is correct
13 Correct 5 ms 884 KB Output is correct
14 Correct 2 ms 852 KB Output is correct
15 Correct 2 ms 756 KB Output is correct
16 Correct 562 ms 756 KB Output is correct
17 Correct 512 ms 756 KB Output is correct
18 Correct 614 ms 756 KB Output is correct
19 Correct 567 ms 736 KB Output is correct
20 Correct 615 ms 756 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 607 ms 1028 KB Output is correct
2 Correct 501 ms 976 KB Output is correct
3 Correct 1186 ms 964 KB Output is correct
4 Correct 667 ms 844 KB Output is correct
5 Correct 553 ms 992 KB Output is correct
6 Correct 441 ms 864 KB Output is correct
7 Correct 459 ms 1012 KB Output is correct
8 Correct 3 ms 856 KB Output is correct
9 Correct 4 ms 736 KB Output is correct
10 Correct 0 ms 852 KB Output is correct
11 Correct 574 ms 784 KB Output is correct
12 Correct 580 ms 756 KB Output is correct
13 Correct 1069 ms 756 KB Output is correct
14 Correct 747 ms 856 KB Output is correct
15 Correct 668 ms 852 KB Output is correct
16 Correct 477 ms 804 KB Output is correct
17 Correct 688 ms 856 KB Output is correct
18 Correct 563 ms 1108 KB Output is correct
19 Correct 481 ms 1080 KB Output is correct
20 Correct 496 ms 736 KB Output is correct
21 Correct 61 ms 856 KB Output is correct
22 Correct 68 ms 932 KB Output is correct
23 Correct 104 ms 904 KB Output is correct
24 Correct 6 ms 892 KB Output is correct
25 Correct 6 ms 756 KB Output is correct
26 Correct 5 ms 852 KB Output is correct
27 Correct 5 ms 964 KB Output is correct
28 Correct 2 ms 736 KB Output is correct
29 Correct 564 ms 856 KB Output is correct
30 Correct 545 ms 736 KB Output is correct
31 Correct 574 ms 736 KB Output is correct
32 Correct 599 ms 856 KB Output is correct
33 Correct 556 ms 856 KB Output is correct
34 Correct 363 ms 996 KB Output is correct
35 Correct 462 ms 1180 KB Output is correct
36 Correct 450 ms 996 KB Output is correct
37 Correct 456 ms 984 KB Output is correct
38 Correct 541 ms 1228 KB Output is correct
39 Correct 550 ms 1228 KB Output is correct
40 Correct 454 ms 1096 KB Output is correct
41 Correct 509 ms 868 KB Output is correct
42 Correct 70 ms 864 KB Output is correct
43 Correct 131 ms 864 KB Output is correct
44 Correct 139 ms 864 KB Output is correct
45 Correct 183 ms 756 KB Output is correct
46 Correct 347 ms 796 KB Output is correct
47 Correct 375 ms 756 KB Output is correct
48 Correct 77 ms 864 KB Output is correct
49 Correct 62 ms 1104 KB Output is correct