Submission #985485

# Submission time Handle Problem Language Result Execution time Memory
985485 2024-05-18T00:48:02 Z efishel Stations (IOI20_stations) C++17
100 / 100
641 ms 1796 KB
#include "stations.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector <ll>;
using vi = vector <int>;

static void dfs (ll u, ll par, ll dep, vi &ans, vector <vll> &adj, ll &timer) {
    if (!(dep&1)) ans[u] = timer++;
    for (ll v : adj[u]) {
        if (v == par) continue;
        dfs(v, u, dep+1, ans, adj, timer);
    }
    if (dep&1) ans[u] += timer++;
}

vi label (int n, int k, vi vu, vi vv) {
    vector <vll> adj(n, vll({}));
    for (ll i = 0; i < n-1; i++) {
        adj[vu[i]].push_back(vv[i]);
        adj[vv[i]].push_back(vu[i]);
    }
    vi ans(n);
    ll timer = 0;
    dfs(0, 0, 0, ans, adj, timer);
    return ans;
}

int find_next_station (int s, int t, vi c) {
    bool isTin = s < c[0];
    if (isTin) { // subtree of s has >= s
        bool isUp = (t < s || (c.size() == 1 ? true : t > c[c.size()-2])) && s != 0; // s==0: s is root
        if (isUp) {
            return c[c.size()-1]; // highest tout -> my par
        } else {
            return *lower_bound(c.begin(), c.end(), t); // first tout above t
        }
    } else { // subtree of s has <= s
        bool isUp = t > s || (c.size() == 1 ? true : t < c[1]);
        if (isUp) {
            return c[0]; // lowest tin -> my par
        } else {
            return *(--upper_bound(c.begin(), c.end(), t)); // tout above t, minus 1 pos
        }
    }
}
# Verdict Execution time Memory Grader output
1 Correct 342 ms 928 KB Output is correct
2 Correct 267 ms 936 KB Output is correct
3 Correct 596 ms 684 KB Output is correct
4 Correct 452 ms 684 KB Output is correct
5 Correct 393 ms 684 KB Output is correct
6 Correct 309 ms 916 KB Output is correct
7 Correct 333 ms 684 KB Output is correct
8 Correct 1 ms 760 KB Output is correct
9 Correct 3 ms 768 KB Output is correct
10 Correct 0 ms 768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 271 ms 1024 KB Output is correct
2 Correct 365 ms 788 KB Output is correct
3 Correct 523 ms 684 KB Output is correct
4 Correct 455 ms 684 KB Output is correct
5 Correct 383 ms 684 KB Output is correct
6 Correct 272 ms 684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 346 ms 932 KB Output is correct
2 Correct 284 ms 936 KB Output is correct
3 Correct 601 ms 684 KB Output is correct
4 Correct 436 ms 684 KB Output is correct
5 Correct 381 ms 684 KB Output is correct
6 Correct 265 ms 912 KB Output is correct
7 Correct 277 ms 684 KB Output is correct
8 Correct 1 ms 768 KB Output is correct
9 Correct 2 ms 768 KB Output is correct
10 Correct 1 ms 852 KB Output is correct
11 Correct 433 ms 684 KB Output is correct
12 Correct 312 ms 1032 KB Output is correct
13 Correct 316 ms 1440 KB Output is correct
14 Correct 262 ms 684 KB Output is correct
15 Correct 32 ms 768 KB Output is correct
16 Correct 43 ms 1112 KB Output is correct
17 Correct 63 ms 944 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 554 ms 936 KB Output is correct
2 Correct 444 ms 684 KB Output is correct
3 Correct 423 ms 684 KB Output is correct
4 Correct 2 ms 768 KB Output is correct
5 Correct 2 ms 764 KB Output is correct
6 Correct 0 ms 764 KB Output is correct
7 Correct 450 ms 684 KB Output is correct
8 Correct 546 ms 684 KB Output is correct
9 Correct 420 ms 684 KB Output is correct
10 Correct 342 ms 684 KB Output is correct
11 Correct 3 ms 768 KB Output is correct
12 Correct 3 ms 768 KB Output is correct
13 Correct 2 ms 768 KB Output is correct
14 Correct 1 ms 768 KB Output is correct
15 Correct 0 ms 764 KB Output is correct
16 Correct 299 ms 688 KB Output is correct
17 Correct 297 ms 680 KB Output is correct
18 Correct 322 ms 684 KB Output is correct
19 Correct 328 ms 684 KB Output is correct
20 Correct 363 ms 684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 347 ms 928 KB Output is correct
2 Correct 261 ms 936 KB Output is correct
3 Correct 641 ms 684 KB Output is correct
4 Correct 385 ms 684 KB Output is correct
5 Correct 357 ms 684 KB Output is correct
6 Correct 300 ms 944 KB Output is correct
7 Correct 290 ms 684 KB Output is correct
8 Correct 1 ms 768 KB Output is correct
9 Correct 2 ms 768 KB Output is correct
10 Correct 0 ms 764 KB Output is correct
11 Correct 278 ms 856 KB Output is correct
12 Correct 360 ms 832 KB Output is correct
13 Correct 547 ms 684 KB Output is correct
14 Correct 426 ms 684 KB Output is correct
15 Correct 424 ms 684 KB Output is correct
16 Correct 278 ms 684 KB Output is correct
17 Correct 394 ms 684 KB Output is correct
18 Correct 275 ms 1164 KB Output is correct
19 Correct 302 ms 1016 KB Output is correct
20 Correct 316 ms 684 KB Output is correct
21 Correct 33 ms 764 KB Output is correct
22 Correct 38 ms 912 KB Output is correct
23 Correct 58 ms 856 KB Output is correct
24 Correct 3 ms 764 KB Output is correct
25 Correct 4 ms 768 KB Output is correct
26 Correct 3 ms 768 KB Output is correct
27 Correct 1 ms 768 KB Output is correct
28 Correct 0 ms 764 KB Output is correct
29 Correct 311 ms 772 KB Output is correct
30 Correct 297 ms 684 KB Output is correct
31 Correct 313 ms 684 KB Output is correct
32 Correct 331 ms 684 KB Output is correct
33 Correct 280 ms 684 KB Output is correct
34 Correct 190 ms 904 KB Output is correct
35 Correct 316 ms 984 KB Output is correct
36 Correct 331 ms 932 KB Output is correct
37 Correct 305 ms 1132 KB Output is correct
38 Correct 356 ms 1120 KB Output is correct
39 Correct 351 ms 976 KB Output is correct
40 Correct 293 ms 1208 KB Output is correct
41 Correct 288 ms 972 KB Output is correct
42 Correct 34 ms 1176 KB Output is correct
43 Correct 61 ms 1200 KB Output is correct
44 Correct 83 ms 864 KB Output is correct
45 Correct 97 ms 860 KB Output is correct
46 Correct 185 ms 864 KB Output is correct
47 Correct 166 ms 904 KB Output is correct
48 Correct 37 ms 1016 KB Output is correct
49 Correct 30 ms 1796 KB Output is correct