Submission #1065791

# Submission time Handle Problem Language Result Execution time Memory
1065791 2024-08-19T11:47:23 Z vjudge1 Stations (IOI20_stations) C++17
100 / 100
657 ms 1472 KB
#include "stations.h"

#include <bits/stdc++.h>

using namespace std;

using vi = vector<int>;

struct tree {
    int n;

    vi sz;
    vector<vi> L;

    tree(int N) : n(N), sz(N, 1), L(N) {}

    void add_edge(int u, int v) {
        L[u].push_back(v);
        L[v].push_back(u);
    }

    vi get_labels() {
        function<void(int, int)> dfs0 = [&](int u, int p) {
            sz[u] = 1;
            for(auto it : L[u]) {
                if(it == p) continue;
                dfs0(it, u);
                sz[u] += sz[it];
            }
        };
        dfs0(0, -1);

        vi Re(n, -1);

        function<void(int, int, int, int, int)> dfs = 
            [&](int u, int p, int l, int r, int tip) {
                if(tip) {
                    Re[u] = l;
                    int v = l + 1;
                    for(auto it : L[u]) {
                        if(it == p) continue;
                        dfs(it, u, v, v + sz[it] - 1, tip ^ 1);
                        v += sz[it];
                    }
                } else {
                    Re[u] = r;
                    int v = r - 1;
                    for(auto it : L[u]) {
                        if(it == p) continue;
                        dfs(it, u, v - sz[it] + 1, v, tip ^ 1);
                        v -= sz[it];
                    }
                }
        };
        dfs(0, -1, 0, n - 1, 0);
       // printf("Labels: ");
       // for(auto it : Re) printf("%d ", it);
       // printf("\n");

        return Re;
    }
};
vi label(int n, int k, vi u, vi v) {
    tree T(n);
    for(int i = 0; i + 1 < n; ++i)
        T.add_edge(u[i], v[i]);

    return T.get_labels();
}

int find_next_station(int s, int t, vi c) {
    int tip = 0;
    for(auto it : c) {
        if(it < s) tip = 1;
    }
    sort(c.begin(), c.end());
    if(!tip) { /// toti din jur sunt mai mari
        if(t < s || t >= c.back()) return c.back();
        for(auto it : c) {
            if(t <= it) return it;
        }
    } else { // toti din jur sunt mai mici
        if(t > s || t <= c[0]) return c[0];
        reverse(c.begin(), c.end());
        for(auto it : c)
            if(t >= it) return it;
    }
}

Compilation message

stations.cpp: In function 'int find_next_station(int, int, vi)':
stations.cpp:88:1: warning: control reaches end of non-void function [-Wreturn-type]
   88 | }
      | ^
# Verdict Execution time Memory Grader output
1 Correct 389 ms 940 KB Output is correct
2 Correct 309 ms 964 KB Output is correct
3 Correct 583 ms 684 KB Output is correct
4 Correct 481 ms 684 KB Output is correct
5 Correct 400 ms 684 KB Output is correct
6 Correct 306 ms 940 KB Output is correct
7 Correct 285 ms 684 KB Output is correct
8 Correct 1 ms 768 KB Output is correct
9 Correct 3 ms 764 KB Output is correct
10 Correct 0 ms 772 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 270 ms 684 KB Output is correct
2 Correct 348 ms 768 KB Output is correct
3 Correct 595 ms 772 KB Output is correct
4 Correct 412 ms 684 KB Output is correct
5 Correct 363 ms 684 KB Output is correct
6 Correct 277 ms 684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 333 ms 940 KB Output is correct
2 Correct 304 ms 940 KB Output is correct
3 Correct 597 ms 688 KB Output is correct
4 Correct 506 ms 936 KB Output is correct
5 Correct 367 ms 684 KB Output is correct
6 Correct 311 ms 944 KB Output is correct
7 Correct 255 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 768 KB Output is correct
11 Correct 335 ms 684 KB Output is correct
12 Correct 305 ms 852 KB Output is correct
13 Correct 260 ms 1056 KB Output is correct
14 Correct 292 ms 684 KB Output is correct
15 Correct 28 ms 764 KB Output is correct
16 Correct 33 ms 856 KB Output is correct
17 Correct 48 ms 752 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 581 ms 684 KB Output is correct
2 Correct 430 ms 936 KB Output is correct
3 Correct 388 ms 684 KB Output is correct
4 Correct 1 ms 772 KB Output is correct
5 Correct 2 ms 768 KB Output is correct
6 Correct 0 ms 768 KB Output is correct
7 Correct 341 ms 768 KB Output is correct
8 Correct 519 ms 684 KB Output is correct
9 Correct 456 ms 684 KB Output is correct
10 Correct 406 ms 684 KB Output is correct
11 Correct 3 ms 768 KB Output is correct
12 Correct 4 ms 768 KB Output is correct
13 Correct 3 ms 760 KB Output is correct
14 Correct 3 ms 768 KB Output is correct
15 Correct 1 ms 776 KB Output is correct
16 Correct 373 ms 768 KB Output is correct
17 Correct 314 ms 684 KB Output is correct
18 Correct 323 ms 684 KB Output is correct
19 Correct 323 ms 684 KB Output is correct
20 Correct 317 ms 684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 365 ms 940 KB Output is correct
2 Correct 293 ms 1196 KB Output is correct
3 Correct 657 ms 684 KB Output is correct
4 Correct 415 ms 684 KB Output is correct
5 Correct 421 ms 684 KB Output is correct
6 Correct 306 ms 940 KB Output is correct
7 Correct 286 ms 684 KB Output is correct
8 Correct 1 ms 764 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 684 KB Output is correct
12 Correct 351 ms 684 KB Output is correct
13 Correct 612 ms 684 KB Output is correct
14 Correct 446 ms 684 KB Output is correct
15 Correct 438 ms 684 KB Output is correct
16 Correct 300 ms 684 KB Output is correct
17 Correct 345 ms 684 KB Output is correct
18 Correct 291 ms 1288 KB Output is correct
19 Correct 314 ms 1444 KB Output is correct
20 Correct 293 ms 684 KB Output is correct
21 Correct 29 ms 764 KB Output is correct
22 Correct 34 ms 772 KB Output is correct
23 Correct 77 ms 716 KB Output is correct
24 Correct 4 ms 764 KB Output is correct
25 Correct 3 ms 768 KB Output is correct
26 Correct 2 ms 768 KB Output is correct
27 Correct 2 ms 764 KB Output is correct
28 Correct 1 ms 760 KB Output is correct
29 Correct 375 ms 684 KB Output is correct
30 Correct 356 ms 684 KB Output is correct
31 Correct 337 ms 684 KB Output is correct
32 Correct 348 ms 684 KB Output is correct
33 Correct 351 ms 684 KB Output is correct
34 Correct 244 ms 940 KB Output is correct
35 Correct 270 ms 940 KB Output is correct
36 Correct 325 ms 940 KB Output is correct
37 Correct 312 ms 784 KB Output is correct
38 Correct 324 ms 776 KB Output is correct
39 Correct 314 ms 932 KB Output is correct
40 Correct 288 ms 772 KB Output is correct
41 Correct 329 ms 1472 KB Output is correct
42 Correct 34 ms 684 KB Output is correct
43 Correct 61 ms 764 KB Output is correct
44 Correct 108 ms 684 KB Output is correct
45 Correct 98 ms 764 KB Output is correct
46 Correct 201 ms 684 KB Output is correct
47 Correct 217 ms 684 KB Output is correct
48 Correct 33 ms 768 KB Output is correct
49 Correct 42 ms 1296 KB Output is correct