Submission #957392

# Submission time Handle Problem Language Result Execution time Memory
957392 2024-04-03T15:51:44 Z steveonalex Stations (IOI20_stations) C++17
0 / 100
575 ms 1184 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 (*lower_bound(ALL(c), t));
        }
        else{
            return c[0];
        }

    }
}

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



//     return 0;
// }
# Verdict Execution time Memory Grader output
1 Incorrect 341 ms 924 KB Wrong query response.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 310 ms 880 KB Wrong query response.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 367 ms 1184 KB Wrong query response.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 575 ms 684 KB Output is correct
2 Correct 391 ms 680 KB Output is correct
3 Incorrect 358 ms 684 KB Wrong query response.
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 331 ms 924 KB Wrong query response.
2 Halted 0 ms 0 KB -