제출 #1131086

#제출 시각아이디문제언어결과실행 시간메모리
1131086NeltStations (IOI20_stations)C++17
100 / 100
452 ms656 KiB
#include "stations.h" #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define ll long long #define endl "\n" using namespace std; using namespace __gnu_pbds; mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); template <typename T, typename key = less<T>> using ordered_set = tree<T, null_type, key, rb_tree_tag, tree_order_statistics_node_update>; const ll N = 1005; vector<ll> g[N]; vector<int> d, f, labels; ll timer = 0; void dfs(ll v, ll par = 0, ll depth = 0) { d[v] = timer++; for (ll to : g[v]) if (to != par) dfs(to, v, depth + 1); f[v] = timer++; if (depth & 1) labels[v] = f[v]; else labels[v] = d[v]; } std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) { timer = 0; d.assign(n, 0); f.assign(n, 0); labels.assign(n, 0); for (ll i = 0; i < n; i++) g[i].clear(); for (ll i = 0; i < n - 1; i++) g[u[i]].push_back(v[i]), g[v[i]].push_back(u[i]); dfs(0); vector<pair<ll, ll>> b; for (ll i = 0; i < n; i++) b.push_back(make_pair(labels[i], i)); sort(b.begin(), b.end()); for (ll i = 0; i < n; i++) labels[b[i].second] = i; return labels; } int find_next_station(int s, int t, std::vector<int> c) { if (s == 0) { for (ll i = 0; i < c.size(); i++) if (t <= c[i]) return c[i]; } if (c.size() == 1) return c[0]; if (c[0] < s) { for (ll i = 1; i + 1 < c.size(); i++) if (c[i] <= t and t <= c[i + 1] - 1) return c[i]; if (c.back() <= t and t <= s) return c.back(); return c[0]; } for (ll i = 1; i + 1 < c.size(); i++) if (c[i - 1] + 1 <= t and t <= c[i]) return c[i]; if (s + 1 <= t and t <= c[0]) return c[0]; return c.back(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...