Submission #979303

# Submission time Handle Problem Language Result Execution time Memory
979303 2024-05-10T14:08:06 Z Zicrus Stations (IOI20_stations) C++17
100 / 100
681 ms 1608 KB
#include <bits/stdc++.h>
#include "stations.h"
using namespace std;

typedef long long ll;

void dfs(vector<vector<int>> &adj, int n, int id, int prev, int &val, vector<int> &res, int layer) {
    if (!(layer & 1)) {
        res[id] += val++;
    }

    for (auto &e : adj[id]) {
        if (e == prev) continue;
        dfs(adj, n, e, id, val, res, layer + 1);
    }
    
    if (layer & 1) {
        res[id] += val++;
    }
}

vector<int> label(int n, int k, vector<int> u, vector<int> v) {
    vector<vector<int>> adj(n);
    for (ll i = 0; i < n-1; i++) {
        adj[u[i]].push_back(v[i]);
        adj[v[i]].push_back(u[i]);
    }
    vector<int> res(n, 0);
    int val = 0;
    dfs(adj, n, 0, -1, val, res, 0);
    return res;
}

int find_next_station(int s, int t, vector<int> c) {
    if (c.size() == 1) return c[0];
    if (s == 0) {
        for (ll i = 0; i <= c.size() - 1; i++) {
            if (c[i] >= t) return c[i];
        }
    }
    bool end = s > c[0];
    if (end) {
        ll parent = c[0];
        ll a = c[1];
        if (t < a || t > s) return parent;
        for (ll i = c.size() - 1; i >= 1; i--) {
            if (c[i] <= t) return c[i];
        }
    }
    else {
        ll parent = c.back();
        ll b = c[c.size() - 2];
        if (t < s || t > b) return parent;
        for (ll i = 0; i <= c.size() - 2; i++) {
            if (c[i] >= t) return c[i];
        }
    }
    return -1;
}

Compilation message

stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:37:26: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |         for (ll i = 0; i <= c.size() - 1; i++) {
      |                        ~~^~~~~~~~~~~~~~~
stations.cpp:54:26: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |         for (ll i = 0; i <= c.size() - 2; i++) {
      |                        ~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 324 ms 940 KB Output is correct
2 Correct 285 ms 1128 KB Output is correct
3 Correct 570 ms 684 KB Output is correct
4 Correct 390 ms 684 KB Output is correct
5 Correct 393 ms 684 KB Output is correct
6 Correct 272 ms 928 KB Output is correct
7 Correct 285 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
# Verdict Execution time Memory Grader output
1 Correct 361 ms 1112 KB Output is correct
2 Correct 326 ms 792 KB Output is correct
3 Correct 572 ms 684 KB Output is correct
4 Correct 449 ms 684 KB Output is correct
5 Correct 386 ms 684 KB Output is correct
6 Correct 305 ms 684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 326 ms 964 KB Output is correct
2 Correct 305 ms 956 KB Output is correct
3 Correct 559 ms 684 KB Output is correct
4 Correct 380 ms 684 KB Output is correct
5 Correct 353 ms 684 KB Output is correct
6 Correct 326 ms 924 KB Output is correct
7 Correct 292 ms 684 KB Output is correct
8 Correct 2 ms 1016 KB Output is correct
9 Correct 3 ms 768 KB Output is correct
10 Correct 0 ms 768 KB Output is correct
11 Correct 356 ms 684 KB Output is correct
12 Correct 307 ms 952 KB Output is correct
13 Correct 319 ms 1288 KB Output is correct
14 Correct 285 ms 684 KB Output is correct
15 Correct 32 ms 768 KB Output is correct
16 Correct 36 ms 904 KB Output is correct
17 Correct 59 ms 852 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 610 ms 684 KB Output is correct
2 Correct 395 ms 684 KB Output is correct
3 Correct 357 ms 684 KB Output is correct
4 Correct 1 ms 768 KB Output is correct
5 Correct 2 ms 768 KB Output is correct
6 Correct 0 ms 768 KB Output is correct
7 Correct 393 ms 684 KB Output is correct
8 Correct 509 ms 684 KB Output is correct
9 Correct 441 ms 680 KB Output is correct
10 Correct 418 ms 684 KB Output is correct
11 Correct 3 ms 764 KB Output is correct
12 Correct 3 ms 768 KB Output is correct
13 Correct 2 ms 768 KB Output is correct
14 Correct 3 ms 768 KB Output is correct
15 Correct 0 ms 768 KB Output is correct
16 Correct 299 ms 684 KB Output is correct
17 Correct 335 ms 684 KB Output is correct
18 Correct 339 ms 684 KB Output is correct
19 Correct 327 ms 684 KB Output is correct
20 Correct 350 ms 684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 407 ms 940 KB Output is correct
2 Correct 334 ms 1112 KB Output is correct
3 Correct 673 ms 684 KB Output is correct
4 Correct 469 ms 768 KB Output is correct
5 Correct 431 ms 864 KB Output is correct
6 Correct 323 ms 1384 KB Output is correct
7 Correct 314 ms 684 KB Output is correct
8 Correct 1 ms 768 KB Output is correct
9 Correct 2 ms 756 KB Output is correct
10 Correct 2 ms 768 KB Output is correct
11 Correct 348 ms 852 KB Output is correct
12 Correct 368 ms 820 KB Output is correct
13 Correct 681 ms 764 KB Output is correct
14 Correct 513 ms 684 KB Output is correct
15 Correct 444 ms 704 KB Output is correct
16 Correct 333 ms 688 KB Output is correct
17 Correct 420 ms 940 KB Output is correct
18 Correct 295 ms 1000 KB Output is correct
19 Correct 342 ms 1540 KB Output is correct
20 Correct 331 ms 776 KB Output is correct
21 Correct 30 ms 764 KB Output is correct
22 Correct 45 ms 908 KB Output is correct
23 Correct 63 ms 1388 KB Output is correct
24 Correct 2 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 3 ms 768 KB Output is correct
28 Correct 1 ms 768 KB Output is correct
29 Correct 328 ms 1028 KB Output is correct
30 Correct 376 ms 864 KB Output is correct
31 Correct 330 ms 940 KB Output is correct
32 Correct 379 ms 688 KB Output is correct
33 Correct 364 ms 684 KB Output is correct
34 Correct 209 ms 1412 KB Output is correct
35 Correct 292 ms 1236 KB Output is correct
36 Correct 321 ms 1608 KB Output is correct
37 Correct 331 ms 1132 KB Output is correct
38 Correct 273 ms 980 KB Output is correct
39 Correct 269 ms 960 KB Output is correct
40 Correct 302 ms 1132 KB Output is correct
41 Correct 275 ms 1392 KB Output is correct
42 Correct 33 ms 916 KB Output is correct
43 Correct 58 ms 856 KB Output is correct
44 Correct 85 ms 852 KB Output is correct
45 Correct 94 ms 860 KB Output is correct
46 Correct 188 ms 860 KB Output is correct
47 Correct 225 ms 896 KB Output is correct
48 Correct 33 ms 1224 KB Output is correct
49 Correct 34 ms 1128 KB Output is correct