Submission #328846

# Submission time Handle Problem Language Result Execution time Memory
328846 2020-11-18T08:07:34 Z dolphingarlic Stations (IOI20_stations) C++14
100 / 100
995 ms 1144 KB
/*
IOI 2020 Stations
- Just alternate between tin and tout
- Complexity: O(N) with max_label == N - 1
*/

#include "stations.h"
#include <vector>
#include <algorithm>

std::vector<int> graph[1000];
int tin[1000], tout[1000], timer;

void dfs(int node = 0, int parent = -1) {
    tin[node] = timer++;
    for (int i : graph[node]) if (i != parent) dfs(i, node);
    tout[node] = timer++;
}

std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) {
    for (int i = 0; i < n; i++) graph[i].clear();
    for (int i = 0; i < n - 1; i++) {
        graph[u[i]].push_back(v[i]);
        graph[v[i]].push_back(u[i]);
    }
    timer = 0;
    dfs();
    std::vector<int> labels(n);
    for (int i = 0; i < n; i++) {
        labels[i] = tin[i] * (tin[i] - 1 & 1) + tout[i] * (tout[i] - 1 & 1) >> 1;
    }
    return labels;
}

int find_next_station(int s, int t, std::vector<int> c) {
    if (s < c.back()) {
        if (t < s || t > c.back()) return c.back();
        return *std::lower_bound(c.begin(), c.end(), t);
    } else {
        if (t > s || t < c[0]) return c[0];
        return *prev(std::upper_bound(c.begin(), c.end(), t));
    }
}

Compilation message

stations.cpp: In function 'std::vector<int> label(int, int, std::vector<int>, std::vector<int>)':
stations.cpp:30:38: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
   30 |         labels[i] = tin[i] * (tin[i] - 1 & 1) + tout[i] * (tout[i] - 1 & 1) >> 1;
      |                               ~~~~~~~^~~
stations.cpp:30:68: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
   30 |         labels[i] = tin[i] * (tin[i] - 1 & 1) + tout[i] * (tout[i] - 1 & 1) >> 1;
      |                                                            ~~~~~~~~^~~
stations.cpp:30:47: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   30 |         labels[i] = tin[i] * (tin[i] - 1 & 1) + tout[i] * (tout[i] - 1 & 1) >> 1;
      |                     ~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 506 ms 884 KB Output is correct
2 Correct 456 ms 884 KB Output is correct
3 Correct 836 ms 756 KB Output is correct
4 Correct 637 ms 884 KB Output is correct
5 Correct 557 ms 848 KB Output is correct
6 Correct 473 ms 876 KB Output is correct
7 Correct 446 ms 756 KB Output is correct
8 Correct 3 ms 856 KB Output is correct
9 Correct 5 ms 848 KB Output is correct
10 Correct 1 ms 736 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 451 ms 796 KB Output is correct
2 Correct 528 ms 756 KB Output is correct
3 Correct 873 ms 848 KB Output is correct
4 Correct 657 ms 1104 KB Output is correct
5 Correct 682 ms 848 KB Output is correct
6 Correct 445 ms 756 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 571 ms 1004 KB Output is correct
2 Correct 519 ms 1004 KB Output is correct
3 Correct 962 ms 780 KB Output is correct
4 Correct 747 ms 1128 KB Output is correct
5 Correct 637 ms 756 KB Output is correct
6 Correct 583 ms 1016 KB Output is correct
7 Correct 556 ms 776 KB Output is correct
8 Correct 3 ms 856 KB Output is correct
9 Correct 5 ms 864 KB Output is correct
10 Correct 0 ms 736 KB Output is correct
11 Correct 652 ms 1128 KB Output is correct
12 Correct 444 ms 1112 KB Output is correct
13 Correct 606 ms 1116 KB Output is correct
14 Correct 493 ms 800 KB Output is correct
15 Correct 70 ms 848 KB Output is correct
16 Correct 58 ms 800 KB Output is correct
17 Correct 111 ms 864 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 847 ms 756 KB Output is correct
2 Correct 677 ms 848 KB Output is correct
3 Correct 686 ms 860 KB Output is correct
4 Correct 3 ms 856 KB Output is correct
5 Correct 5 ms 736 KB Output is correct
6 Correct 0 ms 848 KB Output is correct
7 Correct 586 ms 864 KB Output is correct
8 Correct 995 ms 1000 KB Output is correct
9 Correct 647 ms 756 KB Output is correct
10 Correct 620 ms 756 KB Output is correct
11 Correct 5 ms 756 KB Output is correct
12 Correct 6 ms 736 KB Output is correct
13 Correct 5 ms 756 KB Output is correct
14 Correct 4 ms 756 KB Output is correct
15 Correct 2 ms 856 KB Output is correct
16 Correct 525 ms 736 KB Output is correct
17 Correct 538 ms 756 KB Output is correct
18 Correct 586 ms 848 KB Output is correct
19 Correct 510 ms 756 KB Output is correct
20 Correct 616 ms 848 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 546 ms 780 KB Output is correct
2 Correct 462 ms 1008 KB Output is correct
3 Correct 979 ms 736 KB Output is correct
4 Correct 682 ms 736 KB Output is correct
5 Correct 657 ms 756 KB Output is correct
6 Correct 479 ms 1016 KB Output is correct
7 Correct 507 ms 756 KB Output is correct
8 Correct 2 ms 848 KB Output is correct
9 Correct 4 ms 736 KB Output is correct
10 Correct 1 ms 848 KB Output is correct
11 Correct 468 ms 736 KB Output is correct
12 Correct 572 ms 832 KB Output is correct
13 Correct 919 ms 928 KB Output is correct
14 Correct 710 ms 848 KB Output is correct
15 Correct 640 ms 884 KB Output is correct
16 Correct 480 ms 792 KB Output is correct
17 Correct 600 ms 848 KB Output is correct
18 Correct 507 ms 1120 KB Output is correct
19 Correct 432 ms 992 KB Output is correct
20 Correct 442 ms 800 KB Output is correct
21 Correct 56 ms 796 KB Output is correct
22 Correct 69 ms 924 KB Output is correct
23 Correct 112 ms 1052 KB Output is correct
24 Correct 6 ms 756 KB Output is correct
25 Correct 6 ms 856 KB Output is correct
26 Correct 5 ms 756 KB Output is correct
27 Correct 3 ms 736 KB Output is correct
28 Correct 2 ms 756 KB Output is correct
29 Correct 557 ms 848 KB Output is correct
30 Correct 679 ms 888 KB Output is correct
31 Correct 520 ms 756 KB Output is correct
32 Correct 627 ms 756 KB Output is correct
33 Correct 491 ms 896 KB Output is correct
34 Correct 347 ms 760 KB Output is correct
35 Correct 456 ms 1144 KB Output is correct
36 Correct 446 ms 1112 KB Output is correct
37 Correct 484 ms 992 KB Output is correct
38 Correct 503 ms 1120 KB Output is correct
39 Correct 453 ms 864 KB Output is correct
40 Correct 447 ms 864 KB Output is correct
41 Correct 624 ms 864 KB Output is correct
42 Correct 82 ms 904 KB Output is correct
43 Correct 110 ms 864 KB Output is correct
44 Correct 168 ms 756 KB Output is correct
45 Correct 193 ms 804 KB Output is correct
46 Correct 329 ms 756 KB Output is correct
47 Correct 305 ms 776 KB Output is correct
48 Correct 63 ms 1112 KB Output is correct
49 Correct 65 ms 1100 KB Output is correct