Submission #306080

# Submission time Handle Problem Language Result Execution time Memory
306080 2020-09-24T13:01:47 Z eriksuenderhauf Stations (IOI20_stations) C++17
100 / 100
1047 ms 1280 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<int> deg(n);
  vector<vector<int>> adj(n);
  for (int i = 0; i < n - 1; i++)
    deg[u[i]]++, deg[v[i]]++, adj[u[i]].push_back(v[i]), adj[v[i]].push_back(u[i]);;
  vector<int> labels(n);
  function<void(int,int)> init = [&](int u, int p) {
    if (~p) adj[u].erase(find(adj[u].begin(), adj[u].end(), p));
    for (int v: adj[u])
      init(v, u);
  };
  init(0, -1);
  // function<void(int,int)> dfs;
  // function<void(int,int,int,int)> join = [&](int u, int l, int r, int v) {
  //   if (l > r) return;
  //   if (l == r)
  //     dfs(adj[u][l], 2*v+1);
  //   else {
  //     int m = (l+r) / 2;
  //     join(u, l, m, v*2+1);
  //     join(u, m+1, r, v*2+2);
  //   }
  // };
  // dfs = [&](int u, int l) {
  //   labels[u] = l;
  //   join(u, 0, adj[u].size()-1, l);
  // };
  int l = 0;
  function<void(int,int)> dfs = [&](int u, int d) {
    if (d == 0)
      labels[u] = l++;
    for (int v: adj[u])
      dfs(v, d ^ 1);
    if (d == 1)
      labels[u] = l++;
  };
  dfs(0, 0);
  return labels;
}

int find_next_station(int s, int t, vector<int> c) {
  sort(c.begin(), c.end());
  for (int i: c)
    if (i == t)
      return i;
  if (c.size() > 1) {
    if (s < c[0]) { // d = 0
      int l = s;
      for (int i = 0; i+1 < c.size(); i++) {
        if (l <= t && t <= c[i])
          return c[i];
        l = c[i];
      }
      return c.back();
    } else { // d = 1
      c.push_back(s);
      int l = c[1];
      for (int i = 2; i < c.size(); i++) {
        if (l <= t && t <= c[i])
          return l;
        l = c[i];
      }
    }
  }
  return c[0];
}

Compilation message

stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:53:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |       for (int i = 0; i+1 < c.size(); i++) {
      |                       ~~~~^~~~~~~~~~
stations.cpp:62:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   62 |       for (int i = 2; i < c.size(); i++) {
      |                       ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 532 ms 1008 KB Output is correct
2 Correct 481 ms 976 KB Output is correct
3 Correct 1012 ms 640 KB Output is correct
4 Correct 672 ms 640 KB Output is correct
5 Correct 740 ms 872 KB Output is correct
6 Correct 591 ms 1088 KB Output is correct
7 Correct 484 ms 908 KB Output is correct
8 Correct 3 ms 840 KB Output is correct
9 Correct 5 ms 640 KB Output is correct
10 Correct 2 ms 768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 455 ms 904 KB Output is correct
2 Correct 559 ms 768 KB Output is correct
3 Correct 1047 ms 640 KB Output is correct
4 Correct 720 ms 744 KB Output is correct
5 Correct 621 ms 756 KB Output is correct
6 Correct 525 ms 756 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 552 ms 1000 KB Output is correct
2 Correct 511 ms 1008 KB Output is correct
3 Correct 890 ms 640 KB Output is correct
4 Correct 670 ms 640 KB Output is correct
5 Correct 585 ms 772 KB Output is correct
6 Correct 467 ms 1024 KB Output is correct
7 Correct 476 ms 768 KB Output is correct
8 Correct 3 ms 640 KB Output is correct
9 Correct 5 ms 644 KB Output is correct
10 Correct 2 ms 640 KB Output is correct
11 Correct 610 ms 760 KB Output is correct
12 Correct 480 ms 1244 KB Output is correct
13 Correct 473 ms 1024 KB Output is correct
14 Correct 484 ms 768 KB Output is correct
15 Correct 58 ms 892 KB Output is correct
16 Correct 68 ms 852 KB Output is correct
17 Correct 114 ms 824 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 864 ms 656 KB Output is correct
2 Correct 642 ms 776 KB Output is correct
3 Correct 596 ms 640 KB Output is correct
4 Correct 3 ms 768 KB Output is correct
5 Correct 4 ms 768 KB Output is correct
6 Correct 1 ms 652 KB Output is correct
7 Correct 604 ms 648 KB Output is correct
8 Correct 982 ms 776 KB Output is correct
9 Correct 813 ms 648 KB Output is correct
10 Correct 573 ms 768 KB Output is correct
11 Correct 7 ms 768 KB Output is correct
12 Correct 6 ms 640 KB Output is correct
13 Correct 5 ms 648 KB Output is correct
14 Correct 5 ms 640 KB Output is correct
15 Correct 2 ms 640 KB Output is correct
16 Correct 555 ms 640 KB Output is correct
17 Correct 587 ms 648 KB Output is correct
18 Correct 591 ms 640 KB Output is correct
19 Correct 551 ms 644 KB Output is correct
20 Correct 590 ms 784 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 623 ms 1024 KB Output is correct
2 Correct 542 ms 1008 KB Output is correct
3 Correct 1003 ms 648 KB Output is correct
4 Correct 663 ms 772 KB Output is correct
5 Correct 588 ms 648 KB Output is correct
6 Correct 459 ms 1024 KB Output is correct
7 Correct 436 ms 788 KB Output is correct
8 Correct 3 ms 640 KB Output is correct
9 Correct 5 ms 640 KB Output is correct
10 Correct 2 ms 640 KB Output is correct
11 Correct 466 ms 820 KB Output is correct
12 Correct 514 ms 824 KB Output is correct
13 Correct 903 ms 640 KB Output is correct
14 Correct 797 ms 768 KB Output is correct
15 Correct 705 ms 644 KB Output is correct
16 Correct 535 ms 768 KB Output is correct
17 Correct 731 ms 768 KB Output is correct
18 Correct 588 ms 1280 KB Output is correct
19 Correct 500 ms 1080 KB Output is correct
20 Correct 555 ms 768 KB Output is correct
21 Correct 65 ms 900 KB Output is correct
22 Correct 79 ms 960 KB Output is correct
23 Correct 107 ms 824 KB Output is correct
24 Correct 6 ms 652 KB Output is correct
25 Correct 6 ms 640 KB Output is correct
26 Correct 4 ms 640 KB Output is correct
27 Correct 4 ms 640 KB Output is correct
28 Correct 2 ms 640 KB Output is correct
29 Correct 488 ms 768 KB Output is correct
30 Correct 528 ms 652 KB Output is correct
31 Correct 534 ms 640 KB Output is correct
32 Correct 515 ms 644 KB Output is correct
33 Correct 530 ms 640 KB Output is correct
34 Correct 353 ms 1032 KB Output is correct
35 Correct 458 ms 1024 KB Output is correct
36 Correct 452 ms 1024 KB Output is correct
37 Correct 489 ms 796 KB Output is correct
38 Correct 481 ms 768 KB Output is correct
39 Correct 446 ms 796 KB Output is correct
40 Correct 459 ms 768 KB Output is correct
41 Correct 576 ms 804 KB Output is correct
42 Correct 83 ms 836 KB Output is correct
43 Correct 146 ms 768 KB Output is correct
44 Correct 141 ms 768 KB Output is correct
45 Correct 185 ms 768 KB Output is correct
46 Correct 383 ms 820 KB Output is correct
47 Correct 317 ms 784 KB Output is correct
48 Correct 68 ms 824 KB Output is correct
49 Correct 59 ms 768 KB Output is correct