Submission #1099552

#TimeUsernameProblemLanguageResultExecution timeMemory
1099552TymondStations (IOI20_stations)C++17
69.87 / 100
638 ms1192 KiB
#include <bits/stdc++.h> #include "stations.h" using namespace std; using ll = long long; using ld = long double; #define fi first #define se second #define vi vector<int> #define vll vector<long long> #define pii pair<int, int> #define pll pair<long long, long long> #define pb push_back #define mp make_pair #define eb emplace_back #define all(x) (x).begin(), (x).end() #define sz(x) (int)(x).size() mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count()); mt19937_64 rng64(chrono::high_resolution_clock::now().time_since_epoch().count()); inline int rand(int l,int r){return uniform_int_distribution<int>(l, r)(rng);} inline ll rand(ll l,ll r){return uniform_int_distribution<ll>(l, r)(rng64);} #ifdef DEBUG auto&operator<<(auto&o,pair<auto,auto>p){return o<<"("<<p.first<<", "<<p.second<<")";} auto operator<<(auto&o,auto x)->decltype(x.end(),o){o<<"{";int i=0;for(auto e:x)o<<","+!i++<<e;return o<<"}";} #define debug(X...)cerr<<"["#X"]: ",[](auto...$){((cerr<<$<<"; "),...)<<endl;}(X) #else #define debug(...){} #endif struct custom_hash { static uint64_t splitmix64(uint64_t x) { x += 0x9e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31); } size_t operator()(uint64_t x) const { static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x + FIXED_RANDOM); } }; vi col; int timer = 0; vector<vi> g; void dfs(int v, int p, int f){ if(f == 0){ col[v] = timer++; } for(auto u : g[v]){ if(u == p){ continue; } dfs(u, v, 1 - f); } if(f){ col[v] = timer++; } } vi label(int n, int k, vi u, vi v){ k++; col.assign(n, 0); g.resize(n); for(int i = 0; i < n; i++){ g[i].clear(); } for(int i = 0; i < n - 1; i++){ g[u[i]].pb(v[i]); g[v[i]].pb(u[i]); } dfs(0, 0, 0); return col; } int find_next_station(int s, int t, vi c){ sort(all(c)); if(sz(c) == 1){ return c[0]; } if(s == 0){ for(auto ele : c){ if(t <= ele){ return ele; } } return c.back(); } int cnt[2] = {0, 0}; for(auto ele : c){ if(ele < s){ cnt[1]++; }else{ cnt[0]++; } } if(cnt[0] > cnt[1]){ //fs = 0 for(int i = 0; i + 1 < sz(c); i++){ if(t >= s && t <= c[i]){ return c[i]; } } return c.back(); }else{ //fs = 1 for(int i = sz(c) - 1; i > 0; i--){ if(t >= c[i] && t <= s){ return c[i]; } } return c[0]; } } /*int main(){ vi c = label(5, 10, {0, 1, 1, 2}, {1, 2, 3, 4}); for(int i = 0; i < 5; i++){ cout << c[i] << ' '; } cout << '\n'; cout << find_next_station(c[2], c[0], {c[1], c[4]}) << '\n'; return 0; }*/
#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...