Submission #1062707

# Submission time Handle Problem Language Result Execution time Memory
1062707 2024-08-17T09:56:40 Z jamjanek Stations (IOI20_stations) C++14
100 / 100
656 ms 1052 KB
#include "stations.h"
#include <bits/stdc++.h>
using namespace std;

vector<int>graf[1010];
int pre[1010], it=-1, post[1010];
int dep[1010];
int czyost[1010];
void dfs(int x, int o){
	dep[x] = dep[o]+1;
	pre[x] = ++it;
	if(graf[x].size())
		czyost[graf[x].back()] = 1;
	for(auto j: graf[x])
		if(j!=o)
			dfs(j, x);
	//if(czyost[x])
	it++;
	post[x] = it;
}
vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) {
	int i;
	dep[0] = 0;
	for(i=0;i<n;i++)graf[i].clear();
	for(i=0;i<n;i++)czyost[i] = 0;
	for(i=0;i<n-1;i++){
		graf[u[i]].push_back(v[i]);
		graf[v[i]].push_back(u[i]);
	}
	it= -1;
	dfs(0, 0);
	std::vector<int> labels(n);
	for (int i = 0; i < n; i++) {
		if(dep[i]%2==1)
			labels[i] = pre[i]/2;
		else labels[i] = post[i]/2;
	}
//	for(i=0;i<n;i++)printf("%d: %d %d %d %d\n", i, dep[i], pre[i], post[i], labels[i]);
	return labels;
}

int find_next_station(int s, int t, std::vector<int> c) {
	if(c.size()==1)return c[0];
	int maxi=0;
	for(auto j: c)
		maxi = max(maxi, j);
	if(s>=maxi){
//		printf(" %d\n", s);
		sort(c.begin(), c.end());
		if(t>s)return c[0];
		if(t<c[1])return c[0];
		for(int i=1;i<(int)c.size();i++)
			if(i==(int)c.size()-1 || c[i+1]>t)return c[i];
	}
	sort(c.begin(), c.end());
	if(t<s){
		return c.back();
	}
	if(s==0){
		int pom = *lower_bound(c.begin(), c.end(), t);
		return pom;
	}
	if(t>c[(int)c.size()-1])return c.back();
	int pom = *lower_bound(c.begin(), c.end(), t);
	return pom;
}
# Verdict Execution time Memory Grader output
1 Correct 361 ms 684 KB Output is correct
2 Correct 295 ms 684 KB Output is correct
3 Correct 656 ms 684 KB Output is correct
4 Correct 447 ms 684 KB Output is correct
5 Correct 396 ms 684 KB Output is correct
6 Correct 327 ms 684 KB Output is correct
7 Correct 304 ms 684 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
# Verdict Execution time Memory Grader output
1 Correct 313 ms 684 KB Output is correct
2 Correct 351 ms 688 KB Output is correct
3 Correct 596 ms 684 KB Output is correct
4 Correct 460 ms 684 KB Output is correct
5 Correct 405 ms 684 KB Output is correct
6 Correct 289 ms 684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 392 ms 684 KB Output is correct
2 Correct 297 ms 684 KB Output is correct
3 Correct 580 ms 684 KB Output is correct
4 Correct 471 ms 684 KB Output is correct
5 Correct 385 ms 684 KB Output is correct
6 Correct 297 ms 684 KB Output is correct
7 Correct 288 ms 940 KB Output is correct
8 Correct 1 ms 764 KB Output is correct
9 Correct 1 ms 776 KB Output is correct
10 Correct 1 ms 776 KB Output is correct
11 Correct 413 ms 684 KB Output is correct
12 Correct 339 ms 936 KB Output is correct
13 Correct 369 ms 920 KB Output is correct
14 Correct 276 ms 684 KB Output is correct
15 Correct 29 ms 764 KB Output is correct
16 Correct 31 ms 704 KB Output is correct
17 Correct 68 ms 744 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 602 ms 684 KB Output is correct
2 Correct 469 ms 684 KB Output is correct
3 Correct 428 ms 684 KB Output is correct
4 Correct 1 ms 780 KB Output is correct
5 Correct 1 ms 768 KB Output is correct
6 Correct 0 ms 768 KB Output is correct
7 Correct 405 ms 796 KB Output is correct
8 Correct 634 ms 684 KB Output is correct
9 Correct 495 ms 684 KB Output is correct
10 Correct 397 ms 684 KB Output is correct
11 Correct 2 ms 768 KB Output is correct
12 Correct 2 ms 768 KB Output is correct
13 Correct 2 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 335 ms 796 KB Output is correct
17 Correct 346 ms 684 KB Output is correct
18 Correct 310 ms 684 KB Output is correct
19 Correct 374 ms 684 KB Output is correct
20 Correct 336 ms 940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 382 ms 684 KB Output is correct
2 Correct 277 ms 684 KB Output is correct
3 Correct 613 ms 684 KB Output is correct
4 Correct 465 ms 684 KB Output is correct
5 Correct 409 ms 684 KB Output is correct
6 Correct 292 ms 684 KB Output is correct
7 Correct 317 ms 684 KB Output is correct
8 Correct 2 ms 772 KB Output is correct
9 Correct 3 ms 768 KB Output is correct
10 Correct 0 ms 768 KB Output is correct
11 Correct 337 ms 684 KB Output is correct
12 Correct 378 ms 684 KB Output is correct
13 Correct 557 ms 688 KB Output is correct
14 Correct 405 ms 684 KB Output is correct
15 Correct 399 ms 684 KB Output is correct
16 Correct 276 ms 684 KB Output is correct
17 Correct 434 ms 684 KB Output is correct
18 Correct 313 ms 792 KB Output is correct
19 Correct 334 ms 788 KB Output is correct
20 Correct 316 ms 684 KB Output is correct
21 Correct 30 ms 764 KB Output is correct
22 Correct 33 ms 776 KB Output is correct
23 Correct 75 ms 688 KB Output is correct
24 Correct 2 ms 768 KB Output is correct
25 Correct 2 ms 768 KB Output is correct
26 Correct 3 ms 1028 KB Output is correct
27 Correct 1 ms 768 KB Output is correct
28 Correct 0 ms 768 KB Output is correct
29 Correct 323 ms 684 KB Output is correct
30 Correct 385 ms 684 KB Output is correct
31 Correct 335 ms 684 KB Output is correct
32 Correct 345 ms 684 KB Output is correct
33 Correct 346 ms 684 KB Output is correct
34 Correct 198 ms 716 KB Output is correct
35 Correct 279 ms 684 KB Output is correct
36 Correct 344 ms 684 KB Output is correct
37 Correct 320 ms 788 KB Output is correct
38 Correct 298 ms 940 KB Output is correct
39 Correct 321 ms 1048 KB Output is correct
40 Correct 307 ms 932 KB Output is correct
41 Correct 349 ms 1052 KB Output is correct
42 Correct 31 ms 768 KB Output is correct
43 Correct 65 ms 688 KB Output is correct
44 Correct 90 ms 684 KB Output is correct
45 Correct 99 ms 712 KB Output is correct
46 Correct 219 ms 684 KB Output is correct
47 Correct 175 ms 688 KB Output is correct
48 Correct 42 ms 768 KB Output is correct
49 Correct 31 ms 764 KB Output is correct