Submission #957396

# Submission time Handle Problem Language Result Execution time Memory
957396 2024-04-03T16:00:37 Z steveonalex Stations (IOI20_stations) C++17
100 / 100
618 ms 1752 KB
#include "stations.h"
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define MASK(i) (1LL << (i))
#define GETBIT(mask, i) (((mask) >> (i)) & 1)
#define ALL(v) (v).begin(), (v).end()

ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}

ll LASTBIT(ll mask){return (mask) & (-mask);}
int pop_cnt(ll mask){return __builtin_popcountll(mask);}
int ctz(ll mask){return __builtin_ctzll(mask);}
int logOf(ll mask){return 63 - __builtin_clzll(mask);}

//mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
mt19937_64 rng(69);
ll rngesus(ll l, ll r){return l + (ull) rng() % (r - l + 1);}

template <class T1, class T2>
    bool maximize(T1 &a, T2 b){
        if (a < b) {a = b; return true;}
        return false;
    }

template <class T1, class T2>
    bool minimize(T1 &a, T2 b){
        if (a > b) {a = b; return true;}
        return false;
    }

template <class T>
    void printArr(T& container, string separator = " ", string finish = "\n", ostream &out = cout){
        for(auto item: container) out << item << separator;
        out << finish;
    }

template <class T>
    void remove_dup(vector<T> &a){
        sort(ALL(a));
        a.resize(unique(ALL(a)) - a.begin());
    }

const int N = 1e3 + 69;
vector<int> graph[N];

int dfs_cnt = 0;
int in[N], out[N], h[N];

void dfs(int u, int p){
    in[u] = out[u] = dfs_cnt++;
    for(int v: graph[u]) if (v != p){
        h[v] = h[u] + 1;
        dfs(v, u);
        out[u] = dfs_cnt++;
    }
}

vector<int> label(int n, int k, vector<int> u, vector<int> v) {
    for(int i = 0; i<n; ++i) graph[i].clear();
    for(int i = 0; i<n-1; ++i) {
        graph[u[i]].push_back(v[i]);
        graph[v[i]].push_back(u[i]);
    }

    dfs_cnt = 0;
    h[0] = 0;
    dfs(0, 0);
    vector<int> labels(n);
    for(int i= 0; i<n; ++i) if (h[i] % 2) labels[i] = out[i];
        else labels[i] = in[i];

    vector<int> b = labels;
    remove_dup(b);
    for(int &i: labels) i = lower_bound(ALL(b), i) - b.begin();
    return labels;
}

int find_next_station(int s, int t, vector<int> c) {
    if (s == 0){
        return (*lower_bound(ALL(c), t));
    }
    if (c.size() == 1) return c[0];

    if (s < c[0]){ // h[s] is even
        int l = s, r = c[c.size() - 2];
        if (l <= t && t <= r){
            return (*lower_bound(ALL(c), t));
        }
        else{
            return c.back();
        }
    }
    else{ // h[s] is odd
        int l = c[1], r = s;
        if (l <= t && t <= r){
            return (*(upper_bound(ALL(c), t) - 1));
        }
        else{
            return c[0];
        }

    }
}

// int main(void){
//     ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

//     vector<int> vcl = label(5, 5, {0, 2, 3, 4}, {2, 3, 4, 1});
//     printArr(vcl);

//     cout << find_next_station(0, 2, {4}) << "\n";
//     cout << find_next_station(4, 2, {0, 1}) << "\n";
//     cout << find_next_station(1, 2, {3, 4}) << "\n";
//     cout << find_next_station(3, 2, {1, 2}) << "\n";

//     return 0;
// }
# Verdict Execution time Memory Grader output
1 Correct 332 ms 928 KB Output is correct
2 Correct 308 ms 932 KB Output is correct
3 Correct 569 ms 684 KB Output is correct
4 Correct 441 ms 684 KB Output is correct
5 Correct 369 ms 684 KB Output is correct
6 Correct 294 ms 920 KB Output is correct
7 Correct 267 ms 684 KB Output is correct
8 Correct 1 ms 780 KB Output is correct
9 Correct 3 ms 764 KB Output is correct
10 Correct 1 ms 760 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 304 ms 880 KB Output is correct
2 Correct 336 ms 964 KB Output is correct
3 Correct 584 ms 808 KB Output is correct
4 Correct 407 ms 684 KB Output is correct
5 Correct 358 ms 684 KB Output is correct
6 Correct 295 ms 684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 347 ms 932 KB Output is correct
2 Correct 294 ms 944 KB Output is correct
3 Correct 546 ms 684 KB Output is correct
4 Correct 456 ms 684 KB Output is correct
5 Correct 379 ms 940 KB Output is correct
6 Correct 279 ms 912 KB Output is correct
7 Correct 255 ms 688 KB Output is correct
8 Correct 2 ms 768 KB Output is correct
9 Correct 2 ms 764 KB Output is correct
10 Correct 1 ms 768 KB Output is correct
11 Correct 363 ms 684 KB Output is correct
12 Correct 315 ms 996 KB Output is correct
13 Correct 289 ms 1300 KB Output is correct
14 Correct 293 ms 684 KB Output is correct
15 Correct 44 ms 768 KB Output is correct
16 Correct 39 ms 940 KB Output is correct
17 Correct 64 ms 876 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 571 ms 688 KB Output is correct
2 Correct 419 ms 684 KB Output is correct
3 Correct 354 ms 684 KB Output is correct
4 Correct 1 ms 764 KB Output is correct
5 Correct 3 ms 768 KB Output is correct
6 Correct 0 ms 764 KB Output is correct
7 Correct 390 ms 684 KB Output is correct
8 Correct 592 ms 688 KB Output is correct
9 Correct 477 ms 684 KB Output is correct
10 Correct 388 ms 688 KB Output is correct
11 Correct 2 ms 764 KB Output is correct
12 Correct 4 ms 768 KB Output is correct
13 Correct 3 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 311 ms 684 KB Output is correct
17 Correct 327 ms 684 KB Output is correct
18 Correct 361 ms 684 KB Output is correct
19 Correct 326 ms 684 KB Output is correct
20 Correct 345 ms 684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 339 ms 1300 KB Output is correct
2 Correct 260 ms 924 KB Output is correct
3 Correct 618 ms 684 KB Output is correct
4 Correct 426 ms 684 KB Output is correct
5 Correct 392 ms 688 KB Output is correct
6 Correct 309 ms 940 KB Output is correct
7 Correct 301 ms 684 KB Output is correct
8 Correct 2 ms 764 KB Output is correct
9 Correct 2 ms 1000 KB Output is correct
10 Correct 0 ms 764 KB Output is correct
11 Correct 263 ms 876 KB Output is correct
12 Correct 351 ms 852 KB Output is correct
13 Correct 554 ms 684 KB Output is correct
14 Correct 383 ms 684 KB Output is correct
15 Correct 458 ms 688 KB Output is correct
16 Correct 290 ms 684 KB Output is correct
17 Correct 362 ms 684 KB Output is correct
18 Correct 262 ms 1160 KB Output is correct
19 Correct 286 ms 1296 KB Output is correct
20 Correct 282 ms 684 KB Output is correct
21 Correct 33 ms 764 KB Output is correct
22 Correct 41 ms 1084 KB Output is correct
23 Correct 61 ms 1196 KB Output is correct
24 Correct 5 ms 764 KB Output is correct
25 Correct 3 ms 768 KB Output is correct
26 Correct 3 ms 764 KB Output is correct
27 Correct 2 ms 768 KB Output is correct
28 Correct 2 ms 768 KB Output is correct
29 Correct 342 ms 684 KB Output is correct
30 Correct 303 ms 684 KB Output is correct
31 Correct 327 ms 684 KB Output is correct
32 Correct 339 ms 684 KB Output is correct
33 Correct 361 ms 684 KB Output is correct
34 Correct 186 ms 904 KB Output is correct
35 Correct 261 ms 1312 KB Output is correct
36 Correct 280 ms 1040 KB Output is correct
37 Correct 289 ms 1024 KB Output is correct
38 Correct 287 ms 1168 KB Output is correct
39 Correct 269 ms 1288 KB Output is correct
40 Correct 276 ms 1168 KB Output is correct
41 Correct 290 ms 1028 KB Output is correct
42 Correct 40 ms 916 KB Output is correct
43 Correct 61 ms 976 KB Output is correct
44 Correct 84 ms 904 KB Output is correct
45 Correct 88 ms 904 KB Output is correct
46 Correct 187 ms 876 KB Output is correct
47 Correct 184 ms 900 KB Output is correct
48 Correct 37 ms 1064 KB Output is correct
49 Correct 34 ms 1752 KB Output is correct