Submission #1047101

# Submission time Handle Problem Language Result Execution time Memory
1047101 2024-08-07T08:57:13 Z amirhoseinfar1385 Stations (IOI20_stations) C++17
100 / 100
505 ms 1184 KB
#include "stations.h"
#include<bits/stdc++.h>
using namespace std;
const int maxn=1000+10;
vector<int>ret;
int n,timea=0,k,high[maxn];
vector<int>adj[maxn];

void dfs(int u,int par=-1){
	timea++;
	if(high[u]&1){
		ret[u]=timea;
	}
	for(auto x:adj[u]){
		if(x!=par){
			high[x]=high[u]^1;
			dfs(x,u);
		}
	}
	timea++;
	if((high[u])==0){
		ret[u]=timea;
	}
}

std::vector<int> label(int n_, int k_, std::vector<int> u, std::vector<int> v) {
	n=n_;
	k=k_;
	timea=-1;
	for(int i=0;i<=n;i++){
		adj[i].clear();
	}
	for(int i=0;i<n-1;i++){
		adj[u[i]].push_back(v[i]);
		adj[v[i]].push_back(u[i]);
	}
	high[0]=1;
	ret.clear();
	ret.resize(n);
	dfs(0);
	vector<int>allind;
	for(int i=0;i<n;i++){
		allind.push_back(ret[i]);
	}
	sort(allind.begin(),allind.end());
	for(int i=0;i<n;i++){
		ret[i]=lower_bound(allind.begin(),allind.end(),ret[i])-allind.begin();
	}
	return ret;

}

int find_next_station(int s, int t, std::vector<int> c) {
	vector<int>ch;
	sort(c.begin(),c.end());
	int par=-1;
	if((int)c.size()==1){
		return c[0];
	}
	if(s==0){
		for(int i=0;i<(int)c.size();i++){
			ch.push_back(c[i]);
		}
		int p=lower_bound(ch.begin(),ch.end(),t)-ch.begin();
		return ch[p];
	}else{
		if(s<c[0]){
			par=c.back();
			c.pop_back();
			for(int i=0;i<(int)c.size();i++){
				ch.push_back(c[i]);
			}
			if(!(t>=s&&t<=c.back())){
				return par;
			}
			int p=lower_bound(c.begin(),c.end(),t)-c.begin();
			return c[p];
		}else{
			par=c[0];
			for(int i=1;i<(int)c.size();i++){
				ch.push_back(c[i]);
			}
			if(!(t<=s&&t>=ch[0])){
				return par;
			}
			int p=upper_bound(ch.begin(),ch.end(),t)-ch.begin();
			return ch[p-1];
		}
	}
}
# Verdict Execution time Memory Grader output
1 Correct 302 ms 988 KB Output is correct
2 Correct 252 ms 684 KB Output is correct
3 Correct 473 ms 684 KB Output is correct
4 Correct 373 ms 684 KB Output is correct
5 Correct 336 ms 684 KB Output is correct
6 Correct 241 ms 684 KB Output is correct
7 Correct 260 ms 684 KB Output is correct
8 Correct 1 ms 776 KB Output is correct
9 Correct 2 ms 764 KB Output is correct
10 Correct 0 ms 768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 244 ms 680 KB Output is correct
2 Correct 307 ms 684 KB Output is correct
3 Correct 504 ms 684 KB Output is correct
4 Correct 368 ms 684 KB Output is correct
5 Correct 335 ms 680 KB Output is correct
6 Correct 242 ms 684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 309 ms 940 KB Output is correct
2 Correct 249 ms 684 KB Output is correct
3 Correct 465 ms 684 KB Output is correct
4 Correct 357 ms 684 KB Output is correct
5 Correct 357 ms 940 KB Output is correct
6 Correct 261 ms 684 KB Output is correct
7 Correct 239 ms 688 KB Output is correct
8 Correct 0 ms 768 KB Output is correct
9 Correct 1 ms 768 KB Output is correct
10 Correct 1 ms 768 KB Output is correct
11 Correct 336 ms 684 KB Output is correct
12 Correct 261 ms 788 KB Output is correct
13 Correct 251 ms 932 KB Output is correct
14 Correct 235 ms 684 KB Output is correct
15 Correct 29 ms 768 KB Output is correct
16 Correct 27 ms 768 KB Output is correct
17 Correct 61 ms 716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 505 ms 684 KB Output is correct
2 Correct 374 ms 684 KB Output is correct
3 Correct 335 ms 684 KB Output is correct
4 Correct 1 ms 768 KB Output is correct
5 Correct 2 ms 776 KB Output is correct
6 Correct 0 ms 772 KB Output is correct
7 Correct 335 ms 796 KB Output is correct
8 Correct 487 ms 684 KB Output is correct
9 Correct 359 ms 684 KB Output is correct
10 Correct 304 ms 684 KB Output is correct
11 Correct 3 ms 760 KB Output is correct
12 Correct 3 ms 776 KB Output is correct
13 Correct 2 ms 768 KB Output is correct
14 Correct 1 ms 776 KB Output is correct
15 Correct 1 ms 768 KB Output is correct
16 Correct 275 ms 688 KB Output is correct
17 Correct 302 ms 684 KB Output is correct
18 Correct 291 ms 684 KB Output is correct
19 Correct 274 ms 684 KB Output is correct
20 Correct 288 ms 684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 312 ms 684 KB Output is correct
2 Correct 244 ms 688 KB Output is correct
3 Correct 484 ms 684 KB Output is correct
4 Correct 342 ms 684 KB Output is correct
5 Correct 347 ms 684 KB Output is correct
6 Correct 271 ms 688 KB Output is correct
7 Correct 257 ms 688 KB Output is correct
8 Correct 1 ms 768 KB Output is correct
9 Correct 2 ms 776 KB Output is correct
10 Correct 0 ms 776 KB Output is correct
11 Correct 257 ms 684 KB Output is correct
12 Correct 303 ms 684 KB Output is correct
13 Correct 487 ms 684 KB Output is correct
14 Correct 360 ms 684 KB Output is correct
15 Correct 333 ms 684 KB Output is correct
16 Correct 243 ms 684 KB Output is correct
17 Correct 311 ms 684 KB Output is correct
18 Correct 228 ms 932 KB Output is correct
19 Correct 279 ms 788 KB Output is correct
20 Correct 260 ms 684 KB Output is correct
21 Correct 24 ms 772 KB Output is correct
22 Correct 34 ms 768 KB Output is correct
23 Correct 55 ms 768 KB Output is correct
24 Correct 2 ms 764 KB Output is correct
25 Correct 2 ms 764 KB Output is correct
26 Correct 1 ms 764 KB Output is correct
27 Correct 1 ms 768 KB Output is correct
28 Correct 0 ms 776 KB Output is correct
29 Correct 278 ms 796 KB Output is correct
30 Correct 239 ms 684 KB Output is correct
31 Correct 268 ms 688 KB Output is correct
32 Correct 272 ms 684 KB Output is correct
33 Correct 300 ms 684 KB Output is correct
34 Correct 182 ms 688 KB Output is correct
35 Correct 242 ms 1064 KB Output is correct
36 Correct 267 ms 932 KB Output is correct
37 Correct 243 ms 1044 KB Output is correct
38 Correct 259 ms 1184 KB Output is correct
39 Correct 255 ms 804 KB Output is correct
40 Correct 242 ms 932 KB Output is correct
41 Correct 271 ms 1048 KB Output is correct
42 Correct 27 ms 768 KB Output is correct
43 Correct 55 ms 768 KB Output is correct
44 Correct 66 ms 684 KB Output is correct
45 Correct 95 ms 688 KB Output is correct
46 Correct 176 ms 684 KB Output is correct
47 Correct 158 ms 892 KB Output is correct
48 Correct 37 ms 768 KB Output is correct
49 Correct 38 ms 916 KB Output is correct