Submission #1054807

# Submission time Handle Problem Language Result Execution time Memory
1054807 2024-08-12T12:19:28 Z LittleOrange Stations (IOI20_stations) C++17
100 / 100
563 ms 1272 KB
#include "stations.h"
#include <vector>
#include<bits/stdc++.h>
using namespace std;
using ll = int;

std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) {
	vector<ll> labels(n);
	iota(labels.begin(),labels.end(),0);
	vector<vector<ll>> con(n);
	for(ll i = 0;i<n-1;i++){
		con[u[i]].push_back(v[i]);
		con[v[i]].push_back(u[i]);
	}
	fill(labels.begin(),labels.end(),-1);
	/*for(ll i = 0;i<n;i++){
		if (con[i].size()==1&&labels[i]==-1){
			ll cur = i;
			ll it = 0;
			while(cur!=-1){
				labels[cur] = it++;
				ll nxt = -1;
				for(ll j : con[cur]) if (labels[j]==-1) nxt = j;
				cur = nxt;
			}
		}
	}*/
	/*ll rt = 0;
	for(ll i = 0;i<n;i++) if(con[i].size()>2) rt = i;
	labels[rt] = 0;
	ll gp = 0;
	for(ll i : con[rt]){
		ll g = (++gp)*1000;
		ll x = i;
		while(x!=-1){
			labels[x] = g++;
			ll nw = -1;
			for(ll j : con[x]){
				if(labels[j]==-1){
					nw = j;
				}
			}
			x = nw;
		}
	}*/
	vector<vector<ll>> ch(n);
	vector<ll> sz(n,1);
	{
		function<void(ll,ll)> dfs;
		dfs = [&](ll i, ll p){
			for(ll j : con[i]) if(j!=p){
				ch[i].push_back(j);
				dfs(j,i);
				sz[i]+=sz[j];
			}
		};
		dfs(0,-1);
	}
	{
		function<void(ll,ll,ll)> dfs;
		dfs = [&](ll i, ll it,ll pos){
			if (pos){
				labels[i] = it+sz[i]-1;
			}else{
				labels[i] = it++;
			}
			for(ll j : ch[i]){
				dfs(j, it, pos^1);
				it += sz[j];
			}
		};
		dfs(0,0,0);
	}
	//for(ll i = 0;i<n;i++) cerr << labels[i] << " \n"[i+1==n];
	return labels;
}

int find_next_station(int s, int t, std::vector<int> C) {
	deque<ll> c(C.begin(),C.end());
	//cerr << s << " " << t << " :";
	//for(ll i : c) cerr << " " << i;
	//cerr << "\n";
	/*s++;t++;
	ll lgs = __lg(s), lgt = __lg(t);
	if (lgs<lgt){
		ll x = t>>(lgt-lgs);
		if (s==x){
			return (t>>(lgt-lgs-1))-1;
		}
	}
	return (s>>1)-1;*/
	/*if (t>s) return s+1;
	else return s-1;*/
	/*ll gs = s/1000;
	ll gt = t/1000;
	if (gs==0){
		for(ll i : c){
			if (i/1000==gt) return i;
		}
	}else if(gs==gt){
		if(s>t){
			for(ll i : c){
				if (i<s) return i;
			}
		}else{
			for(ll i : c){
				if (i>s) return i;
			}
		}
	}else{
		for(ll i : c){
			if (i<s) return i;
		}
	}*/
	sort(c.begin(),c.end());
	if(s==0){
		for(ll i : c) if(i>=t) return i;
	}else{
		if (s<c[0]){
			ll pa = c.back();c.pop_back();
			if (t<s||c.empty()||t>c.back()) return pa;
			for(ll i : c) if(i>=t) return i;
		}else{
			ll pa = c.front();c.pop_front();
			if (t>s||c.empty()||t<c.front()) return pa;
			reverse(c.begin(),c.end());
			for(ll i : c) if(i<=t) return i;
		}
	}
	return -1;
}
# Verdict Execution time Memory Grader output
1 Correct 327 ms 940 KB Output is correct
2 Correct 272 ms 940 KB Output is correct
3 Correct 481 ms 684 KB Output is correct
4 Correct 400 ms 684 KB Output is correct
5 Correct 305 ms 684 KB Output is correct
6 Correct 243 ms 940 KB Output is correct
7 Correct 218 ms 940 KB Output is correct
8 Correct 1 ms 764 KB Output is correct
9 Correct 1 ms 768 KB Output is correct
10 Correct 0 ms 768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 261 ms 776 KB Output is correct
2 Correct 315 ms 684 KB Output is correct
3 Correct 509 ms 684 KB Output is correct
4 Correct 387 ms 684 KB Output is correct
5 Correct 289 ms 684 KB Output is correct
6 Correct 255 ms 936 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 292 ms 940 KB Output is correct
2 Correct 259 ms 940 KB Output is correct
3 Correct 484 ms 684 KB Output is correct
4 Correct 377 ms 684 KB Output is correct
5 Correct 305 ms 684 KB Output is correct
6 Correct 264 ms 940 KB Output is correct
7 Correct 256 ms 1192 KB Output is correct
8 Correct 1 ms 764 KB Output is correct
9 Correct 1 ms 768 KB Output is correct
10 Correct 0 ms 776 KB Output is correct
11 Correct 347 ms 684 KB Output is correct
12 Correct 239 ms 1016 KB Output is correct
13 Correct 252 ms 1272 KB Output is correct
14 Correct 236 ms 772 KB Output is correct
15 Correct 27 ms 772 KB Output is correct
16 Correct 32 ms 832 KB Output is correct
17 Correct 56 ms 744 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 431 ms 684 KB Output is correct
2 Correct 392 ms 684 KB Output is correct
3 Correct 320 ms 684 KB Output is correct
4 Correct 2 ms 776 KB Output is correct
5 Correct 1 ms 768 KB Output is correct
6 Correct 0 ms 764 KB Output is correct
7 Correct 340 ms 772 KB Output is correct
8 Correct 520 ms 684 KB Output is correct
9 Correct 380 ms 684 KB Output is correct
10 Correct 341 ms 684 KB Output is correct
11 Correct 2 ms 780 KB Output is correct
12 Correct 2 ms 768 KB Output is correct
13 Correct 1 ms 776 KB Output is correct
14 Correct 1 ms 764 KB Output is correct
15 Correct 0 ms 768 KB Output is correct
16 Correct 279 ms 688 KB Output is correct
17 Correct 290 ms 684 KB Output is correct
18 Correct 294 ms 684 KB Output is correct
19 Correct 303 ms 684 KB Output is correct
20 Correct 284 ms 684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 321 ms 940 KB Output is correct
2 Correct 255 ms 944 KB Output is correct
3 Correct 549 ms 684 KB Output is correct
4 Correct 362 ms 684 KB Output is correct
5 Correct 332 ms 684 KB Output is correct
6 Correct 253 ms 940 KB Output is correct
7 Correct 236 ms 940 KB Output is correct
8 Correct 0 ms 772 KB Output is correct
9 Correct 1 ms 768 KB Output is correct
10 Correct 1 ms 764 KB Output is correct
11 Correct 243 ms 684 KB Output is correct
12 Correct 327 ms 684 KB Output is correct
13 Correct 563 ms 684 KB Output is correct
14 Correct 347 ms 684 KB Output is correct
15 Correct 384 ms 684 KB Output is correct
16 Correct 227 ms 684 KB Output is correct
17 Correct 284 ms 684 KB Output is correct
18 Correct 254 ms 1032 KB Output is correct
19 Correct 239 ms 1032 KB Output is correct
20 Correct 232 ms 684 KB Output is correct
21 Correct 34 ms 716 KB Output is correct
22 Correct 38 ms 680 KB Output is correct
23 Correct 72 ms 736 KB Output is correct
24 Correct 1 ms 768 KB Output is correct
25 Correct 2 ms 768 KB Output is correct
26 Correct 2 ms 780 KB Output is correct
27 Correct 1 ms 780 KB Output is correct
28 Correct 0 ms 768 KB Output is correct
29 Correct 294 ms 684 KB Output is correct
30 Correct 276 ms 688 KB Output is correct
31 Correct 270 ms 684 KB Output is correct
32 Correct 290 ms 688 KB Output is correct
33 Correct 281 ms 772 KB Output is correct
34 Correct 174 ms 772 KB Output is correct
35 Correct 234 ms 1032 KB Output is correct
36 Correct 205 ms 1196 KB Output is correct
37 Correct 246 ms 1020 KB Output is correct
38 Correct 250 ms 684 KB Output is correct
39 Correct 234 ms 1028 KB Output is correct
40 Correct 271 ms 1040 KB Output is correct
41 Correct 267 ms 784 KB Output is correct
42 Correct 27 ms 744 KB Output is correct
43 Correct 53 ms 744 KB Output is correct
44 Correct 64 ms 684 KB Output is correct
45 Correct 80 ms 684 KB Output is correct
46 Correct 184 ms 684 KB Output is correct
47 Correct 152 ms 940 KB Output is correct
48 Correct 28 ms 764 KB Output is correct
49 Correct 31 ms 804 KB Output is correct