Submission #634355

# Submission time Handle Problem Language Result Execution time Memory
634355 2022-08-24T09:23:27 Z tabr Stations (IOI20_stations) C++17
100 / 100
880 ms 832 KB
#include <bits/stdc++.h>
using namespace std;
#ifdef tabr
#include "library/debug.cpp"
#else
#define debug(...)
#endif

// editorial?

vector<int> label(int n, int k, vector<int> x, vector<int> y) {
    vector<vector<int>> g(n);
    for (int i = 0; i < n - 1; i++) {
        g[x[i]].emplace_back(y[i]);
        g[y[i]].emplace_back(x[i]);
    }
    vector<int> depth(n), sz(n);
    {
        function<void(int, int)> Dfs = [&](int v, int p) {
            sz[v]++;
            for (int to : g[v]) {
                if (to == p) {
                    continue;
                }
                depth[to] = depth[v] + 1;
                Dfs(to, v);
                sz[v] += sz[to];
            }
        };
        Dfs(0, -1);
    }
    vector<int> res(n);
    function<void(int, int, int, int)> Dfs = [&](int v, int p, int low, int high) {
        if (depth[v] % 2 == 0) {
            res[v] = low;
            low++;
        } else {
            res[v] = high - 1;
            high--;
        }
        for (int to : g[v]) {
            if (to == p) {
                continue;
            }
            Dfs(to, v, low, low + sz[to]);
            low += sz[to];
        }
        assert(low == high);
    };
    Dfs(0, -1, 0, n);
    return res;
}

int find_next_station(int s, int t, vector<int> c) {
    sort(c.begin(), c.end());
    if (c[0] < s) {
        reverse(c.begin(), c.end());
        for (int v : c) {
            if (v <= t && t < s) {
                return v;
            }
        }
    } else {
        for (int v : c) {
            if (s < t && t <= v) {
                return v;
            }
        }
    }
    return c.back();
}

#ifdef tabr
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    return 0;
}
#endif
# Verdict Execution time Memory Grader output
1 Correct 533 ms 672 KB Output is correct
2 Correct 408 ms 676 KB Output is correct
3 Correct 809 ms 416 KB Output is correct
4 Correct 598 ms 416 KB Output is correct
5 Correct 515 ms 504 KB Output is correct
6 Correct 394 ms 676 KB Output is correct
7 Correct 362 ms 548 KB Output is correct
8 Correct 2 ms 500 KB Output is correct
9 Correct 4 ms 496 KB Output is correct
10 Correct 0 ms 500 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 417 ms 484 KB Output is correct
2 Correct 529 ms 632 KB Output is correct
3 Correct 718 ms 416 KB Output is correct
4 Correct 670 ms 420 KB Output is correct
5 Correct 553 ms 420 KB Output is correct
6 Correct 431 ms 548 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 512 ms 624 KB Output is correct
2 Correct 427 ms 628 KB Output is correct
3 Correct 880 ms 416 KB Output is correct
4 Correct 574 ms 504 KB Output is correct
5 Correct 451 ms 416 KB Output is correct
6 Correct 445 ms 632 KB Output is correct
7 Correct 417 ms 536 KB Output is correct
8 Correct 2 ms 492 KB Output is correct
9 Correct 1 ms 508 KB Output is correct
10 Correct 1 ms 492 KB Output is correct
11 Correct 455 ms 500 KB Output is correct
12 Correct 361 ms 832 KB Output is correct
13 Correct 468 ms 724 KB Output is correct
14 Correct 416 ms 544 KB Output is correct
15 Correct 54 ms 444 KB Output is correct
16 Correct 53 ms 572 KB Output is correct
17 Correct 91 ms 624 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 836 ms 496 KB Output is correct
2 Correct 662 ms 508 KB Output is correct
3 Correct 467 ms 492 KB Output is correct
4 Correct 2 ms 500 KB Output is correct
5 Correct 4 ms 492 KB Output is correct
6 Correct 0 ms 492 KB Output is correct
7 Correct 540 ms 508 KB Output is correct
8 Correct 851 ms 420 KB Output is correct
9 Correct 609 ms 508 KB Output is correct
10 Correct 604 ms 420 KB Output is correct
11 Correct 3 ms 488 KB Output is correct
12 Correct 3 ms 492 KB Output is correct
13 Correct 4 ms 492 KB Output is correct
14 Correct 4 ms 500 KB Output is correct
15 Correct 2 ms 492 KB Output is correct
16 Correct 436 ms 504 KB Output is correct
17 Correct 499 ms 424 KB Output is correct
18 Correct 483 ms 504 KB Output is correct
19 Correct 478 ms 420 KB Output is correct
20 Correct 483 ms 416 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 469 ms 628 KB Output is correct
2 Correct 455 ms 668 KB Output is correct
3 Correct 853 ms 416 KB Output is correct
4 Correct 696 ms 504 KB Output is correct
5 Correct 584 ms 416 KB Output is correct
6 Correct 457 ms 672 KB Output is correct
7 Correct 385 ms 572 KB Output is correct
8 Correct 2 ms 492 KB Output is correct
9 Correct 3 ms 500 KB Output is correct
10 Correct 1 ms 492 KB Output is correct
11 Correct 446 ms 500 KB Output is correct
12 Correct 525 ms 512 KB Output is correct
13 Correct 705 ms 416 KB Output is correct
14 Correct 470 ms 416 KB Output is correct
15 Correct 554 ms 416 KB Output is correct
16 Correct 399 ms 544 KB Output is correct
17 Correct 523 ms 420 KB Output is correct
18 Correct 476 ms 724 KB Output is correct
19 Correct 557 ms 752 KB Output is correct
20 Correct 448 ms 500 KB Output is correct
21 Correct 58 ms 492 KB Output is correct
22 Correct 60 ms 568 KB Output is correct
23 Correct 107 ms 512 KB Output is correct
24 Correct 5 ms 500 KB Output is correct
25 Correct 3 ms 500 KB Output is correct
26 Correct 3 ms 496 KB Output is correct
27 Correct 2 ms 492 KB Output is correct
28 Correct 1 ms 492 KB Output is correct
29 Correct 452 ms 492 KB Output is correct
30 Correct 531 ms 420 KB Output is correct
31 Correct 488 ms 512 KB Output is correct
32 Correct 443 ms 420 KB Output is correct
33 Correct 424 ms 420 KB Output is correct
34 Correct 278 ms 688 KB Output is correct
35 Correct 424 ms 676 KB Output is correct
36 Correct 389 ms 676 KB Output is correct
37 Correct 426 ms 632 KB Output is correct
38 Correct 440 ms 624 KB Output is correct
39 Correct 376 ms 624 KB Output is correct
40 Correct 451 ms 632 KB Output is correct
41 Correct 393 ms 752 KB Output is correct
42 Correct 65 ms 600 KB Output is correct
43 Correct 94 ms 500 KB Output is correct
44 Correct 140 ms 548 KB Output is correct
45 Correct 154 ms 508 KB Output is correct
46 Correct 316 ms 508 KB Output is correct
47 Correct 245 ms 548 KB Output is correct
48 Correct 54 ms 572 KB Output is correct
49 Correct 50 ms 572 KB Output is correct