Submission #362050

# Submission time Handle Problem Language Result Execution time Memory
362050 2021-02-01T16:15:36 Z valerikk Stations (IOI20_stations) C++17
100 / 100
1099 ms 1280 KB
#include <bits/stdc++.h>
using namespace std; 

const int N = 1007;
vector<int> g[N];
int a[N], b[N], C, dep[N];

void dfs(int v,int d = 0, int p =-1){
    a[v] = C++;
    dep[v] = d;
    for(int u : g[v]){
        if (u!= p) {
            dfs(u, d + 1, v);
        }
    }
    b[v] = C++;
}

vector<int> label(int n, int k, vector<int> u, vector<int> v) {
    for (int i = 0;i < n; i++) g[i].clear();
    for (int i = 0;i < n - 1; i++) {
        g[u[i]].push_back(v[i]);
        g[v[i]].push_back(u[i]);
    }
    C = 0;
    dfs(0);
    vector<int> L(n), LL;
    for(int i =0 ; i < n ; i++) {
        L[i] = (dep[i]&1) ? b[i] : a[i];
        LL.push_back(L[i]);
    }
    sort(LL.begin(), LL.end());
    for (int i = 0; i < n; i++) L[i] = lower_bound(LL.begin(), LL.end(), L[i]) - LL.begin();
    return L;
}

int find_next_station(int s, int t, vector<int> c) {
    for (int v : c) {
        if (v == t) return v;
    }
    bool f = 1;
    for (int v : c) f &= v > s;
    if (f) {
        int lst = s;
        for (int i = 0; i < c.size(); i++) {
            if (i == (int)c.size() - 1) return c[i];
            if (t > lst && t < c[i]) return c[i];
            lst = c[i];
        }
        assert(0);
        return -1;
    }
    int lst = s;
    for (int i = (int)c.size() - 1; i >= 0; i--){
        if (i == 0) return c[i];
        if (t < lst && t > c[i]) return c[i];
        lst = c[i];
    }
    assert(0);
    return -1;
}

Compilation message

stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:45:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |         for (int i = 0; i < c.size(); i++) {
      |                         ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 525 ms 864 KB Output is correct
2 Correct 583 ms 992 KB Output is correct
3 Correct 1099 ms 864 KB Output is correct
4 Correct 782 ms 900 KB Output is correct
5 Correct 705 ms 864 KB Output is correct
6 Correct 646 ms 1084 KB Output is correct
7 Correct 583 ms 992 KB Output is correct
8 Correct 3 ms 736 KB Output is correct
9 Correct 4 ms 736 KB Output is correct
10 Correct 1 ms 736 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 620 ms 864 KB Output is correct
2 Correct 602 ms 736 KB Output is correct
3 Correct 923 ms 736 KB Output is correct
4 Correct 733 ms 1108 KB Output is correct
5 Correct 713 ms 864 KB Output is correct
6 Correct 467 ms 864 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 602 ms 900 KB Output is correct
2 Correct 481 ms 992 KB Output is correct
3 Correct 1061 ms 772 KB Output is correct
4 Correct 798 ms 748 KB Output is correct
5 Correct 676 ms 940 KB Output is correct
6 Correct 521 ms 1080 KB Output is correct
7 Correct 482 ms 900 KB Output is correct
8 Correct 2 ms 864 KB Output is correct
9 Correct 4 ms 736 KB Output is correct
10 Correct 2 ms 864 KB Output is correct
11 Correct 692 ms 948 KB Output is correct
12 Correct 484 ms 1280 KB Output is correct
13 Correct 551 ms 1248 KB Output is correct
14 Correct 503 ms 736 KB Output is correct
15 Correct 68 ms 864 KB Output is correct
16 Correct 66 ms 896 KB Output is correct
17 Correct 153 ms 864 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 924 ms 940 KB Output is correct
2 Correct 750 ms 864 KB Output is correct
3 Correct 641 ms 940 KB Output is correct
4 Correct 3 ms 804 KB Output is correct
5 Correct 6 ms 864 KB Output is correct
6 Correct 2 ms 940 KB Output is correct
7 Correct 707 ms 864 KB Output is correct
8 Correct 1053 ms 940 KB Output is correct
9 Correct 770 ms 940 KB Output is correct
10 Correct 589 ms 992 KB Output is correct
11 Correct 5 ms 948 KB Output is correct
12 Correct 6 ms 736 KB Output is correct
13 Correct 4 ms 864 KB Output is correct
14 Correct 5 ms 864 KB Output is correct
15 Correct 2 ms 736 KB Output is correct
16 Correct 565 ms 1068 KB Output is correct
17 Correct 550 ms 940 KB Output is correct
18 Correct 610 ms 900 KB Output is correct
19 Correct 686 ms 864 KB Output is correct
20 Correct 599 ms 864 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 737 ms 1076 KB Output is correct
2 Correct 569 ms 1076 KB Output is correct
3 Correct 1035 ms 736 KB Output is correct
4 Correct 792 ms 940 KB Output is correct
5 Correct 618 ms 832 KB Output is correct
6 Correct 424 ms 1080 KB Output is correct
7 Correct 446 ms 1112 KB Output is correct
8 Correct 5 ms 948 KB Output is correct
9 Correct 6 ms 736 KB Output is correct
10 Correct 1 ms 736 KB Output is correct
11 Correct 494 ms 872 KB Output is correct
12 Correct 588 ms 864 KB Output is correct
13 Correct 888 ms 864 KB Output is correct
14 Correct 789 ms 736 KB Output is correct
15 Correct 806 ms 864 KB Output is correct
16 Correct 562 ms 864 KB Output is correct
17 Correct 692 ms 940 KB Output is correct
18 Correct 464 ms 992 KB Output is correct
19 Correct 469 ms 1148 KB Output is correct
20 Correct 448 ms 864 KB Output is correct
21 Correct 55 ms 736 KB Output is correct
22 Correct 73 ms 736 KB Output is correct
23 Correct 121 ms 872 KB Output is correct
24 Correct 7 ms 864 KB Output is correct
25 Correct 7 ms 940 KB Output is correct
26 Correct 6 ms 736 KB Output is correct
27 Correct 5 ms 736 KB Output is correct
28 Correct 2 ms 736 KB Output is correct
29 Correct 646 ms 900 KB Output is correct
30 Correct 656 ms 736 KB Output is correct
31 Correct 499 ms 948 KB Output is correct
32 Correct 708 ms 832 KB Output is correct
33 Correct 841 ms 940 KB Output is correct
34 Correct 430 ms 992 KB Output is correct
35 Correct 428 ms 1072 KB Output is correct
36 Correct 546 ms 992 KB Output is correct
37 Correct 518 ms 988 KB Output is correct
38 Correct 562 ms 864 KB Output is correct
39 Correct 602 ms 1220 KB Output is correct
40 Correct 580 ms 1108 KB Output is correct
41 Correct 483 ms 1224 KB Output is correct
42 Correct 81 ms 884 KB Output is correct
43 Correct 104 ms 864 KB Output is correct
44 Correct 141 ms 1240 KB Output is correct
45 Correct 171 ms 864 KB Output is correct
46 Correct 379 ms 864 KB Output is correct
47 Correct 382 ms 992 KB Output is correct
48 Correct 78 ms 872 KB Output is correct
49 Correct 64 ms 1036 KB Output is correct