Submission #921479

# Submission time Handle Problem Language Result Execution time Memory
921479 2024-02-04T00:55:34 Z ksujay2 Stations (IOI20_stations) C++17
100 / 100
620 ms 1388 KB
#include <bits/stdc++.h>
using namespace std;

vector<int> label(int n, int k, vector<int> u, vector<int> v) {
    vector<vector<int>> adj(n);
    for(int i = 0; i < n - 1; i++) {
        adj[u[i]].push_back(v[i]);
        adj[v[i]].push_back(u[i]);
    }
    int t = 0;
    vector<int> label(n);
    function<void(int, int, int)> dfs = [&] (int s, int e, int p) {
        if(!p) label[s] = t++;
        for(int u : adj[s]) {
            if(u != e) {
                dfs(u, s, p ^ 1);
            }
        }
        if(p) label[s] = t++;
    };
    dfs(0, -1, 0);
    return label;
}

int find_next_station(int s, int t, vector<int> c) {
    bool mn = true;
    for(int u : c) {
        if(u < s) {
            mn = false;
        }
    }
    if(mn) {
        int p = c.back();
        if(s <= t && t <= p - 1) {
            int prev = s + 1;
            for(int i = 0; i < c.size() - 1; i++) {
                if(prev <= t && t <= c[i]) {
                    return c[i];
                }
                prev = c[i] + 1;
            }
            assert(true);
        } else {
            return p;
        }
    } else {
        int p = c[0];
        if(p + 1 <= t && t <= s) {
            int prev = s - 1;
            for(int i = c.size() - 1; i > 0; i--) {
                if(c[i] <= t && t <= prev) {
                    return c[i];
                }
                prev = c[i] + 1;
            }
            assert(true);
        } else {
            return p;
        }
    }
}

Compilation message

stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:36:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |             for(int i = 0; i < c.size() - 1; i++) {
      |                            ~~^~~~~~~~~~~~~~
stations.cpp:61:1: warning: control reaches end of non-void function [-Wreturn-type]
   61 | }
      | ^
# Verdict Execution time Memory Grader output
1 Correct 320 ms 944 KB Output is correct
2 Correct 282 ms 948 KB Output is correct
3 Correct 534 ms 940 KB Output is correct
4 Correct 446 ms 688 KB Output is correct
5 Correct 342 ms 684 KB Output is correct
6 Correct 269 ms 936 KB Output is correct
7 Correct 265 ms 684 KB Output is correct
8 Correct 1 ms 768 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 289 ms 852 KB Output is correct
2 Correct 313 ms 792 KB Output is correct
3 Correct 526 ms 684 KB Output is correct
4 Correct 467 ms 684 KB Output is correct
5 Correct 368 ms 684 KB Output is correct
6 Correct 291 ms 684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 365 ms 948 KB Output is correct
2 Correct 241 ms 956 KB Output is correct
3 Correct 501 ms 684 KB Output is correct
4 Correct 484 ms 936 KB Output is correct
5 Correct 358 ms 684 KB Output is correct
6 Correct 289 ms 928 KB Output is correct
7 Correct 261 ms 684 KB Output is correct
8 Correct 1 ms 768 KB Output is correct
9 Correct 2 ms 764 KB Output is correct
10 Correct 0 ms 768 KB Output is correct
11 Correct 395 ms 940 KB Output is correct
12 Correct 303 ms 956 KB Output is correct
13 Correct 287 ms 1292 KB Output is correct
14 Correct 305 ms 940 KB Output is correct
15 Correct 30 ms 768 KB Output is correct
16 Correct 38 ms 900 KB Output is correct
17 Correct 60 ms 888 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 563 ms 684 KB Output is correct
2 Correct 373 ms 684 KB Output is correct
3 Correct 393 ms 684 KB Output is correct
4 Correct 2 ms 768 KB Output is correct
5 Correct 3 ms 768 KB Output is correct
6 Correct 0 ms 764 KB Output is correct
7 Correct 412 ms 684 KB Output is correct
8 Correct 620 ms 684 KB Output is correct
9 Correct 448 ms 936 KB Output is correct
10 Correct 391 ms 684 KB Output is correct
11 Correct 4 ms 768 KB Output is correct
12 Correct 2 ms 768 KB Output is correct
13 Correct 3 ms 768 KB Output is correct
14 Correct 3 ms 768 KB Output is correct
15 Correct 2 ms 768 KB Output is correct
16 Correct 315 ms 684 KB Output is correct
17 Correct 372 ms 684 KB Output is correct
18 Correct 353 ms 684 KB Output is correct
19 Correct 372 ms 688 KB Output is correct
20 Correct 380 ms 684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 300 ms 948 KB Output is correct
2 Correct 270 ms 940 KB Output is correct
3 Correct 501 ms 940 KB Output is correct
4 Correct 443 ms 684 KB Output is correct
5 Correct 356 ms 684 KB Output is correct
6 Correct 260 ms 956 KB Output is correct
7 Correct 258 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 768 KB Output is correct
11 Correct 301 ms 844 KB Output is correct
12 Correct 327 ms 824 KB Output is correct
13 Correct 549 ms 940 KB Output is correct
14 Correct 437 ms 684 KB Output is correct
15 Correct 336 ms 684 KB Output is correct
16 Correct 230 ms 684 KB Output is correct
17 Correct 330 ms 684 KB Output is correct
18 Correct 330 ms 1180 KB Output is correct
19 Correct 335 ms 1288 KB Output is correct
20 Correct 263 ms 684 KB Output is correct
21 Correct 33 ms 768 KB Output is correct
22 Correct 38 ms 864 KB Output is correct
23 Correct 56 ms 916 KB Output is correct
24 Correct 4 ms 764 KB Output is correct
25 Correct 3 ms 768 KB Output is correct
26 Correct 3 ms 760 KB Output is correct
27 Correct 2 ms 768 KB Output is correct
28 Correct 1 ms 772 KB Output is correct
29 Correct 361 ms 684 KB Output is correct
30 Correct 327 ms 684 KB Output is correct
31 Correct 338 ms 684 KB Output is correct
32 Correct 272 ms 684 KB Output is correct
33 Correct 325 ms 684 KB Output is correct
34 Correct 181 ms 908 KB Output is correct
35 Correct 244 ms 1224 KB Output is correct
36 Correct 244 ms 1188 KB Output is correct
37 Correct 256 ms 1112 KB Output is correct
38 Correct 246 ms 1116 KB Output is correct
39 Correct 260 ms 1124 KB Output is correct
40 Correct 262 ms 1128 KB Output is correct
41 Correct 251 ms 1388 KB Output is correct
42 Correct 33 ms 868 KB Output is correct
43 Correct 65 ms 852 KB Output is correct
44 Correct 93 ms 872 KB Output is correct
45 Correct 89 ms 880 KB Output is correct
46 Correct 172 ms 864 KB Output is correct
47 Correct 187 ms 904 KB Output is correct
48 Correct 32 ms 856 KB Output is correct
49 Correct 35 ms 1224 KB Output is correct