Submission #985493

# Submission time Handle Problem Language Result Execution time Memory
985493 2024-05-18T01:20:13 Z Maaxle Stations (IOI20_stations) C++17
0 / 100
623 ms 1176 KB
#include "stations.h"
#include <bits/stdc++.h>

#define range(it, a, b) for (ll it = a; it < b; it++)
#define all(x) begin(x), end(x)
#define ll long long
#define ull unsigned long long
#define INF64 ((ll) 1 << 62)
#define INF32 (1 << 30)
#define mset multiset
#define uset unordered_set
#define umap unordered_map 
#define pqueue priority_queue 
#define ptr(A) shared_ptr<A>

using namespace std;

struct Node {
    int in, out;
    int depth;
};

vector<Node> nodes;
vector<vector<int>> adj;
vector<int> euler;

void dfs(int i, int p, int d) {
    nodes[i].depth = d;
    nodes[i].in = euler.size();
    euler.push_back(i);

    for (int& k : adj[i]) {
        if (k != p)
            dfs(k, i, d+1);
    }

    nodes[i].out = euler.size();
    euler.push_back(i);    
}

vector<int> label(int n, int k, vector<int> u, vector<int> v) {
    nodes.clear();
    nodes.resize(n);
    
    adj.clear();
    adj.resize(n);

    euler.clear();

    range(i, 0, n-1) {
        adj[u[i]].push_back(v[i]);
        adj[v[i]].push_back(u[i]);
    }

    dfs(0, 0, 0);

    vector<int> label (n);
    range(i, 0, n) 
        label[i] = (nodes[i].depth & 1 ? nodes[i].out : nodes[i].in);
    sort(all(label));

    vector<int> ans (n);
    range(i, 0, n) {
        int bs = (nodes[i].depth & 1 ? nodes[i].out : nodes[i].in);
        ans[i] = distance(begin(label), lower_bound(all(label), bs));
    }
    return ans;
}
		

int find_next_station(int s, int t, vector<int> c) {
    if (c.size() == 1)
        return c[0];
    sort(all(c));
    
    // CASE 0 -> s is the root (node 0)
    // t has to be a decendant of some c
    // ancestor of t is the first that is >= t
    if (s == 0) {
        for (int& i : c) {
            if (i >= t)
                return i;
        }
    }

    // CASE 1 -> s has an 'in' value
    // every node in c has value 'out'
    // the parent of them all is the right-most value
    // s is the left-most value
    if (s < c[0]) {

        // CASE 1.1 -> t is not a decendant of s
        // and t is before s
        if (t < s) 
            return c.back();
            

        // CASE 1.2 -> t may or not be decendant of s
        // ancestor of t is the first in c that is >= t
        for (int& i : c) {
            if (i >= t)
                return i;
        }
    }

    // CASE 2 -> s has an 'out' value
    // every node in c has value 'in'
    // the parent of them all is the left-most value
    // s is the right-most value
    
    // CASE 2.1 -> t is not a decendant of s
    //  and t is after s
    if (t > s) 
        return c[0];
        
    
    // CASE 2.2 -> t may or may not be a decendant of s
    // ancestor of t is the first in c that is <= t (backwards)
    for (auto it = rbegin(c); 1; it++) {
        if (*it <= t)
            return *it;
    }
}
# Verdict Execution time Memory Grader output
1 Incorrect 389 ms 956 KB Wrong query response.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 292 ms 1056 KB Wrong query response.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 387 ms 1176 KB Wrong query response.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 623 ms 684 KB Output is correct
2 Correct 412 ms 684 KB Output is correct
3 Correct 355 ms 684 KB Output is correct
4 Correct 1 ms 768 KB Output is correct
5 Incorrect 3 ms 768 KB Wrong query response.
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 352 ms 960 KB Wrong query response.
2 Halted 0 ms 0 KB -