Submission #503208

# Submission time Handle Problem Language Result Execution time Memory
503208 2022-01-07T13:46:33 Z WongChun1234 Stations (IOI20_stations) C++14
100 / 100
948 ms 752 KB
#include "stations.h"
#include <vector>
#include<bits/stdc++.h>
using namespace std;

int ret[1050],sz[1050];
vector<int> adj[1050];
void calcsze(int id,int par=-1){
	sz[id]=1;
	for (int i:adj[id]){
		if (i==par) continue;
		calcsze(i,id);
		sz[id]+=sz[i];
	}
}
void dfs(int id,int par,int l,int r,bool bck){
	if (bck) ret[id]=r;
	else ret[id]=l;
	int curr=l+(!bck);
	for (int i:adj[id]){
		if (i==par) continue;
		dfs(i,id,curr,curr+sz[i]-1,!bck);
		curr+=sz[i];
	}
}
std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) {
	std::vector<int> labels(n);
	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]);
	}
	calcsze(0);
	dfs(0,-1,0,n-1,0);
	for (int i = 0; i < n; i++) {
		labels[i] = ret[i];
	}
	return labels;
}

int find_next_station(int s, int t, std::vector<int> c) {
	sort(c.begin(),c.end());
	if (c[0]<s){
		//current one is back
		for (int i=1;i<(int)c.size();i++){
			if (t<c[i]) return c[i-1];
		}
		if (t<s) return c.back();
		return c[0];
	}else{
		//current one is front
		if (t<s) return c.back();
		for (int i:c) if (t<=i) return i;
		return c.back();
	}
}
# Verdict Execution time Memory Grader output
1 Correct 534 ms 680 KB Output is correct
2 Correct 382 ms 752 KB Output is correct
3 Correct 853 ms 504 KB Output is correct
4 Correct 509 ms 400 KB Output is correct
5 Correct 620 ms 512 KB Output is correct
6 Correct 424 ms 520 KB Output is correct
7 Correct 371 ms 488 KB Output is correct
8 Correct 3 ms 468 KB Output is correct
9 Correct 3 ms 616 KB Output is correct
10 Correct 1 ms 600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 436 ms 640 KB Output is correct
2 Correct 471 ms 488 KB Output is correct
3 Correct 808 ms 404 KB Output is correct
4 Correct 569 ms 488 KB Output is correct
5 Correct 545 ms 492 KB Output is correct
6 Correct 451 ms 492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 509 ms 656 KB Output is correct
2 Correct 399 ms 524 KB Output is correct
3 Correct 864 ms 492 KB Output is correct
4 Correct 693 ms 400 KB Output is correct
5 Correct 620 ms 512 KB Output is correct
6 Correct 478 ms 636 KB Output is correct
7 Correct 438 ms 508 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 2 ms 464 KB Output is correct
10 Correct 0 ms 556 KB Output is correct
11 Correct 618 ms 508 KB Output is correct
12 Correct 385 ms 660 KB Output is correct
13 Correct 453 ms 628 KB Output is correct
14 Correct 350 ms 524 KB Output is correct
15 Correct 45 ms 548 KB Output is correct
16 Correct 60 ms 652 KB Output is correct
17 Correct 100 ms 700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 934 ms 400 KB Output is correct
2 Correct 617 ms 516 KB Output is correct
3 Correct 592 ms 404 KB Output is correct
4 Correct 2 ms 448 KB Output is correct
5 Correct 4 ms 480 KB Output is correct
6 Correct 0 ms 476 KB Output is correct
7 Correct 550 ms 508 KB Output is correct
8 Correct 948 ms 416 KB Output is correct
9 Correct 614 ms 404 KB Output is correct
10 Correct 520 ms 520 KB Output is correct
11 Correct 6 ms 476 KB Output is correct
12 Correct 5 ms 592 KB Output is correct
13 Correct 3 ms 468 KB Output is correct
14 Correct 4 ms 468 KB Output is correct
15 Correct 2 ms 604 KB Output is correct
16 Correct 461 ms 404 KB Output is correct
17 Correct 353 ms 488 KB Output is correct
18 Correct 493 ms 400 KB Output is correct
19 Correct 497 ms 492 KB Output is correct
20 Correct 395 ms 508 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 490 ms 620 KB Output is correct
2 Correct 402 ms 520 KB Output is correct
3 Correct 763 ms 492 KB Output is correct
4 Correct 638 ms 404 KB Output is correct
5 Correct 578 ms 508 KB Output is correct
6 Correct 483 ms 520 KB Output is correct
7 Correct 449 ms 524 KB Output is correct
8 Correct 1 ms 480 KB Output is correct
9 Correct 3 ms 468 KB Output is correct
10 Correct 0 ms 608 KB Output is correct
11 Correct 489 ms 528 KB Output is correct
12 Correct 475 ms 504 KB Output is correct
13 Correct 768 ms 504 KB Output is correct
14 Correct 554 ms 508 KB Output is correct
15 Correct 570 ms 400 KB Output is correct
16 Correct 471 ms 532 KB Output is correct
17 Correct 560 ms 492 KB Output is correct
18 Correct 438 ms 608 KB Output is correct
19 Correct 443 ms 624 KB Output is correct
20 Correct 449 ms 524 KB Output is correct
21 Correct 45 ms 528 KB Output is correct
22 Correct 83 ms 548 KB Output is correct
23 Correct 111 ms 688 KB Output is correct
24 Correct 4 ms 468 KB Output is correct
25 Correct 4 ms 596 KB Output is correct
26 Correct 5 ms 492 KB Output is correct
27 Correct 3 ms 468 KB Output is correct
28 Correct 1 ms 508 KB Output is correct
29 Correct 476 ms 404 KB Output is correct
30 Correct 451 ms 492 KB Output is correct
31 Correct 459 ms 512 KB Output is correct
32 Correct 409 ms 492 KB Output is correct
33 Correct 477 ms 508 KB Output is correct
34 Correct 333 ms 504 KB Output is correct
35 Correct 428 ms 732 KB Output is correct
36 Correct 447 ms 616 KB Output is correct
37 Correct 431 ms 728 KB Output is correct
38 Correct 489 ms 604 KB Output is correct
39 Correct 343 ms 636 KB Output is correct
40 Correct 444 ms 648 KB Output is correct
41 Correct 379 ms 644 KB Output is correct
42 Correct 67 ms 548 KB Output is correct
43 Correct 115 ms 592 KB Output is correct
44 Correct 125 ms 512 KB Output is correct
45 Correct 173 ms 512 KB Output is correct
46 Correct 302 ms 520 KB Output is correct
47 Correct 284 ms 508 KB Output is correct
48 Correct 80 ms 656 KB Output is correct
49 Correct 61 ms 684 KB Output is correct