Submission #1074136

# Submission time Handle Problem Language Result Execution time Memory
1074136 2024-08-25T08:16:25 Z TheQuantiX Stations (IOI20_stations) C++17
100 / 100
626 ms 1328 KB
#include <bits/stdc++.h>
#include "stations.h"

using namespace std;
using ll = long long;

ll n, m, q, k, x, y, a, b, c;
vector<ll> G[1000];

void dfs(ll x, ll p, ll depth, ll &timer, vector<int> &ans) {
    // cout << x << ' ' << p << ' ' << depth << ' ' << timer << endl;
    if (depth % 2 == 0) {
        ans[x] = timer;
    }
    timer++;
    for (int i : G[x]) {
        if (i != p) {
            dfs(i, x, depth + 1, timer, ans);
        }
    }
    if (depth % 2 == 1) {
        ans[x] = timer;
    }
    timer++;
}

vector<int> label(int N, int K, vector<int> u, vector<int> v) {
    n = N;
    k = K;
    for (int i = 0; i < 1000; i++) {
        G[i].clear();
    }
    for (int i = 0; i < u.size(); i++) {
        G[u[i]].push_back(v[i]);
        G[v[i]].push_back(u[i]);
    }
    vector<int> ans(n);
    ll timer = 0;
    dfs(0, -1, 0, timer, ans);
    set<ll> st;
    for (int i = 0; i < n; i++) {
        st.insert(ans[i]);
    }
    map<ll, ll> mp;
    ll cnt = 0;
    for (int i : st) {
        mp[i] = cnt++;
    }
    for (int i = 0; i < n; i++) {
        ans[i] = mp[ans[i]];
    }
    return ans;
}

int find_next_station(int s, int t, vector<int> c) {
    // cout << s << ' ' << t << '\n';
    // for (int i = 0; i < c.size(); i++) {
    //     cout << c[i] << ' ';
    // }
    // cout << '\n';
    if (s > c[c.size() - 1]) {
        for (int i = 1; i < c.size(); i++) {
            if (c[i] > t) {
                return c[i - 1];
            }
        }
        if (s > t) {
            return c[c.size() - 1];
        }
        return c[0];
    }
    if (s > t) {
        return c[c.size() - 1];
    }
    for (int i = 0; i < c.size() - 1; i++) {
        if (c[i] >= t) {
            return c[i];
        }
    }
    return c[c.size() - 1];
}

Compilation message

stations.cpp: In function 'std::vector<int> label(int, int, std::vector<int>, std::vector<int>)':
stations.cpp:33:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |     for (int i = 0; i < u.size(); i++) {
      |                     ~~^~~~~~~~~~
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:62:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   62 |         for (int i = 1; i < c.size(); i++) {
      |                         ~~^~~~~~~~~~
stations.cpp:75:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   75 |     for (int i = 0; i < c.size() - 1; i++) {
      |                     ~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 381 ms 1200 KB Output is correct
2 Correct 329 ms 940 KB Output is correct
3 Correct 619 ms 792 KB Output is correct
4 Correct 391 ms 684 KB Output is correct
5 Correct 389 ms 800 KB Output is correct
6 Correct 291 ms 940 KB Output is correct
7 Correct 286 ms 944 KB Output is correct
8 Correct 2 ms 768 KB Output is correct
9 Correct 3 ms 768 KB Output is correct
10 Correct 1 ms 768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 289 ms 940 KB Output is correct
2 Correct 379 ms 940 KB Output is correct
3 Correct 582 ms 684 KB Output is correct
4 Correct 452 ms 688 KB Output is correct
5 Correct 358 ms 684 KB Output is correct
6 Correct 307 ms 940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 346 ms 940 KB Output is correct
2 Correct 294 ms 940 KB Output is correct
3 Correct 559 ms 684 KB Output is correct
4 Correct 446 ms 684 KB Output is correct
5 Correct 391 ms 684 KB Output is correct
6 Correct 329 ms 940 KB Output is correct
7 Correct 330 ms 940 KB Output is correct
8 Correct 2 ms 768 KB Output is correct
9 Correct 1 ms 768 KB Output is correct
10 Correct 1 ms 764 KB Output is correct
11 Correct 391 ms 684 KB Output is correct
12 Correct 292 ms 1044 KB Output is correct
13 Correct 342 ms 1048 KB Output is correct
14 Correct 311 ms 940 KB Output is correct
15 Correct 27 ms 736 KB Output is correct
16 Correct 39 ms 736 KB Output is correct
17 Correct 65 ms 1108 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 544 ms 684 KB Output is correct
2 Correct 379 ms 684 KB Output is correct
3 Correct 370 ms 684 KB Output is correct
4 Correct 1 ms 764 KB Output is correct
5 Correct 2 ms 768 KB Output is correct
6 Correct 1 ms 764 KB Output is correct
7 Correct 369 ms 684 KB Output is correct
8 Correct 540 ms 684 KB Output is correct
9 Correct 458 ms 684 KB Output is correct
10 Correct 402 ms 684 KB Output is correct
11 Correct 3 ms 764 KB Output is correct
12 Correct 2 ms 768 KB Output is correct
13 Correct 2 ms 768 KB Output is correct
14 Correct 2 ms 768 KB Output is correct
15 Correct 1 ms 768 KB Output is correct
16 Correct 304 ms 684 KB Output is correct
17 Correct 310 ms 684 KB Output is correct
18 Correct 308 ms 684 KB Output is correct
19 Correct 328 ms 684 KB Output is correct
20 Correct 331 ms 684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 364 ms 940 KB Output is correct
2 Correct 320 ms 940 KB Output is correct
3 Correct 575 ms 684 KB Output is correct
4 Correct 501 ms 684 KB Output is correct
5 Correct 383 ms 684 KB Output is correct
6 Correct 297 ms 940 KB Output is correct
7 Correct 291 ms 1100 KB Output is correct
8 Correct 2 ms 1020 KB Output is correct
9 Correct 3 ms 772 KB Output is correct
10 Correct 0 ms 788 KB Output is correct
11 Correct 258 ms 940 KB Output is correct
12 Correct 375 ms 940 KB Output is correct
13 Correct 626 ms 684 KB Output is correct
14 Correct 460 ms 684 KB Output is correct
15 Correct 375 ms 684 KB Output is correct
16 Correct 325 ms 940 KB Output is correct
17 Correct 403 ms 684 KB Output is correct
18 Correct 300 ms 940 KB Output is correct
19 Correct 349 ms 1296 KB Output is correct
20 Correct 305 ms 940 KB Output is correct
21 Correct 28 ms 768 KB Output is correct
22 Correct 38 ms 700 KB Output is correct
23 Correct 67 ms 1108 KB Output is correct
24 Correct 2 ms 768 KB Output is correct
25 Correct 2 ms 776 KB Output is correct
26 Correct 2 ms 776 KB Output is correct
27 Correct 1 ms 768 KB Output is correct
28 Correct 1 ms 768 KB Output is correct
29 Correct 318 ms 688 KB Output is correct
30 Correct 329 ms 684 KB Output is correct
31 Correct 329 ms 684 KB Output is correct
32 Correct 349 ms 684 KB Output is correct
33 Correct 362 ms 684 KB Output is correct
34 Correct 195 ms 944 KB Output is correct
35 Correct 296 ms 1196 KB Output is correct
36 Correct 325 ms 940 KB Output is correct
37 Correct 322 ms 1188 KB Output is correct
38 Correct 318 ms 1044 KB Output is correct
39 Correct 320 ms 1300 KB Output is correct
40 Correct 285 ms 1188 KB Output is correct
41 Correct 343 ms 1328 KB Output is correct
42 Correct 41 ms 972 KB Output is correct
43 Correct 66 ms 992 KB Output is correct
44 Correct 72 ms 1020 KB Output is correct
45 Correct 100 ms 1000 KB Output is correct
46 Correct 193 ms 960 KB Output is correct
47 Correct 218 ms 940 KB Output is correct
48 Correct 36 ms 1128 KB Output is correct
49 Correct 30 ms 976 KB Output is correct