Submission #1073793

# Submission time Handle Problem Language Result Execution time Memory
1073793 2024-08-24T21:24:07 Z thatsgonzalez Stations (IOI20_stations) C++14
69.868 / 100
627 ms 1700 KB
#include "stations.h"
#include <vector>

#include <bits/stdc++.h>
using namespace std;


#define pb push_back

int mn = 0;
map<int,bool> mp;

int dfs(int node, int p, vector<vector<int>> &g, vector<int> &sub_tree){

	for(auto &x: g[node]){
		if(x == p) continue;

		sub_tree[node]+=dfs(x,node,g,sub_tree);

	}

	return sub_tree[node]=sub_tree[node]+1;

}

void calc_labels(int node, int p, int t, vector<vector<int>> &g, vector<int> &sub_tree, vector<int> &labels){
	if(t){
		while(mp[mn]) mn++;
		mp[mn+sub_tree[node]-1] = 1;
		labels[node] = mn+sub_tree[node]-1;
		while(mp[mn]) mn++;
	}
	else{
		while(mp[mn]) mn++;
		mp[mn] = 1;
		labels[node] = mn; 
		while(mp[mn]) mn++;
	}
	for(auto &x: g[node]){
		if(x == p) continue;
		int turno = t^1;
		calc_labels(x,node,turno,g,sub_tree,labels);
	}

}

std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) {
	
	vector<int> sub_tree(n,0);
	vector<vector<int>> g(n);
	vector<int> labels(n);

	for(int i = 0; i<n-1; i++){
		g[u[i]].pb(v[i]);
		g[v[i]].pb(u[i]);
	}


	dfs(0,-1,g,sub_tree);
	calc_labels(0,-1,1,g,sub_tree,labels);


	return labels;
}

int find_next_station(int s, int t, std::vector<int> c) {
	
	if(c[0]>s){
		int l = s;
		for(int i = 0; i<c.size()-1; i++){
			if(t>=l and t<=c[i]){
				return c[i];
			}
			else l = c[i]+1;
		}
		return c.back();
	}
	else{
		int r = s;
		for(int i = c.size()-1; i; i--){
			if(t>=c[i] and t<=r) return c[i];
			else r = c[i]-1;
		}
		return c[0];
	}

}

Compilation message

stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:70:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   70 |   for(int i = 0; i<c.size()-1; i++){
      |                  ~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 760 KB Invalid labels (values out of range). scenario=2, k=1000, vertex=0, label=1010
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 852 KB Invalid labels (values out of range). scenario=1, k=1000, vertex=0, label=1989
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 349 ms 1196 KB Output is correct
2 Correct 305 ms 1196 KB Output is correct
3 Correct 620 ms 684 KB Output is correct
4 Correct 479 ms 684 KB Output is correct
5 Correct 425 ms 684 KB Output is correct
6 Correct 304 ms 1196 KB Output is correct
7 Correct 308 ms 940 KB Output is correct
8 Correct 1 ms 772 KB Output is correct
9 Correct 1 ms 776 KB Output is correct
10 Correct 0 ms 768 KB Output is correct
11 Correct 385 ms 684 KB Output is correct
12 Correct 305 ms 1280 KB Output is correct
13 Correct 307 ms 1268 KB Output is correct
14 Correct 268 ms 684 KB Output is correct
15 Correct 26 ms 768 KB Output is correct
16 Correct 37 ms 1024 KB Output is correct
17 Correct 83 ms 1256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 593 ms 684 KB Output is correct
2 Correct 450 ms 684 KB Output is correct
3 Correct 399 ms 684 KB Output is correct
4 Correct 1 ms 780 KB Output is correct
5 Correct 2 ms 768 KB Output is correct
6 Correct 1 ms 768 KB Output is correct
7 Correct 417 ms 684 KB Output is correct
8 Correct 627 ms 936 KB Output is correct
9 Correct 473 ms 684 KB Output is correct
10 Correct 424 ms 684 KB Output is correct
11 Correct 3 ms 768 KB Output is correct
12 Correct 2 ms 768 KB Output is correct
13 Correct 2 ms 768 KB Output is correct
14 Correct 1 ms 764 KB Output is correct
15 Correct 0 ms 768 KB Output is correct
16 Correct 381 ms 684 KB Output is correct
17 Correct 331 ms 684 KB Output is correct
18 Correct 347 ms 684 KB Output is correct
19 Correct 349 ms 684 KB Output is correct
20 Correct 364 ms 684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Partially correct 370 ms 1196 KB Partially correct
2 Partially correct 333 ms 1196 KB Partially correct
3 Correct 604 ms 684 KB Output is correct
4 Correct 436 ms 684 KB Output is correct
5 Correct 417 ms 684 KB Output is correct
6 Partially correct 295 ms 1196 KB Partially correct
7 Correct 314 ms 940 KB Output is correct
8 Correct 1 ms 776 KB Output is correct
9 Correct 3 ms 776 KB Output is correct
10 Correct 0 ms 768 KB Output is correct
11 Partially correct 298 ms 1200 KB Partially correct
12 Partially correct 377 ms 940 KB Partially correct
13 Correct 588 ms 684 KB Output is correct
14 Correct 421 ms 684 KB Output is correct
15 Correct 407 ms 684 KB Output is correct
16 Correct 304 ms 684 KB Output is correct
17 Correct 417 ms 684 KB Output is correct
18 Partially correct 338 ms 1272 KB Partially correct
19 Partially correct 313 ms 1272 KB Partially correct
20 Correct 289 ms 684 KB Output is correct
21 Correct 26 ms 684 KB Output is correct
22 Partially correct 39 ms 1020 KB Partially correct
23 Partially correct 52 ms 1396 KB Partially correct
24 Correct 2 ms 764 KB Output is correct
25 Correct 2 ms 760 KB Output is correct
26 Correct 2 ms 768 KB Output is correct
27 Correct 1 ms 776 KB Output is correct
28 Correct 0 ms 776 KB Output is correct
29 Correct 351 ms 684 KB Output is correct
30 Correct 336 ms 684 KB Output is correct
31 Correct 347 ms 684 KB Output is correct
32 Correct 337 ms 684 KB Output is correct
33 Correct 388 ms 684 KB Output is correct
34 Partially correct 202 ms 1188 KB Partially correct
35 Partially correct 297 ms 1700 KB Partially correct
36 Partially correct 317 ms 1196 KB Partially correct
37 Partially correct 342 ms 1276 KB Partially correct
38 Partially correct 299 ms 1272 KB Partially correct
39 Partially correct 340 ms 1280 KB Partially correct
40 Partially correct 290 ms 1452 KB Partially correct
41 Partially correct 307 ms 1532 KB Partially correct
42 Partially correct 46 ms 1024 KB Partially correct
43 Partially correct 63 ms 1376 KB Partially correct
44 Partially correct 81 ms 1180 KB Partially correct
45 Partially correct 98 ms 1200 KB Partially correct
46 Partially correct 228 ms 1196 KB Partially correct
47 Partially correct 164 ms 1196 KB Partially correct
48 Partially correct 39 ms 1252 KB Partially correct
49 Partially correct 31 ms 1380 KB Partially correct