Submission #379479

# Submission time Handle Problem Language Result Execution time Memory
379479 2021-03-18T10:03:26 Z rocks03 Stations (IOI20_stations) C++14
0 / 100
916 ms 1332 KB
//#pragma GCC target("avx2")
//#pragma GCC optimization("O3")
//#pragma GCC optimization("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define ff first
#define ss second
#define pb push_back
#define SZ(x) ((int)(x).size())
#define all(x) x.begin(), x.end()
#define rep(i, a, b) for(int i = (a); i < (b); i++)
#define Re(i, a, b) for(int i = (a); i >= (b); i--)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int MAXN = 1e3;
vector<vector<int>> g;

int timer;
void dfs(int v, int p, vector<int>& labels){
    int tin = timer++;
    for(int u : g[v]){
        if(u ^ p){
            dfs(u, v, labels);
        }
    }
    int tou = timer - 1;
    labels[v] = MAXN * tin + tou;
}

vector<int> label(int N, int K, vector<int> u, vector<int> v){
    g.resize(N);
    rep(i, 0, N){
        g[i].clear();
    }
    auto add_edge = [&](int a, int b){
        g[a].pb(b);
        g[b].pb(a);
    };
    rep(i, 0, N - 1){
        add_edge(u[i], v[i]);
    }
    vector<int> labels(N);
    timer = 0;
    dfs(0, -1, labels);
    return labels;
}

int find_next_station(int a, int b, vector<int> c){
    auto get_label = [&](int x){
        pii ans = {x / MAXN, x % MAXN};
        return ans;
    };
    auto ancestor = [&] (pii u, pii v){
        bool is = (u.ff <= v.ff && v.ss <= u.ss);
        return is;
    };
    pii s = get_label(a), t = get_label(b);
    for(int x : c){
        pii u = get_label(x);
        if(ancestor(s, u)){
            if(ancestor(u, t))
                return x;
        } else{
            if(ancestor(t, u))
                return x;
        }
    }
}

Compilation message

stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:71:1: warning: control reaches end of non-void function [-Wreturn-type]
   71 | }
      | ^
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 492 KB Invalid labels (values out of range). scenario=0, k=1000, vertex=1, label=6009
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 364 KB Invalid labels (values out of range). scenario=0, k=1000, vertex=1, label=1511
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 4 ms 1120 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 916 ms 736 KB Output is correct
2 Runtime error 2 ms 1100 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 4 ms 1332 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -