Submission #1045309

# Submission time Handle Problem Language Result Execution time Memory
1045309 2024-08-05T20:15:43 Z n1k Stations (IOI20_stations) C++17
100 / 100
559 ms 1188 KB
#include "stations.h"
#include <vector>
#include <bits/stdc++.h>

using namespace std;

std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) {
	vector<vector<int>> g(n);
	for(int i=0; i+1<n; i++){
		g[u[i]].push_back(v[i]);
		g[v[i]].push_back(u[i]);
	}
	vector<int> l(n);
	int t = 0;
	function<void(int, int, int)> dfs = [&](int u, int d, int p){
		if(d%2==0){
			l[u]=t++;
		}
		for(int v:g[u]){
			if(v==p){
				continue;
			}
			dfs(v, d+1, u);	
		}
		if(d%2==1){
			l[u]=t++;
		}
	};
	dfs(0, 0, -1);
	return l;
}

int find_next_station(int s, int t, std::vector<int> c) {
	if(c.size()==1){
		return c[0];
	}
	if(c.back()<s){
		// saved time is tout
		// check if we hold it
		int tin = c[1], tout = s;
		if(not (tin <= t and t <= tout)){
			return c[0];
		}
		for(int i=1; i<c.size(); i++){
			tin = c[i], tout = (i+1 < c.size() ? c[i+1] : s);
			if(tin <= t and t < tout){
				return c[i];
			}
		}
		// we hold it if tin <= t < tout or s == 0
		// if not go to par
	}else{
		int tin = s, tout = c[c.size()-2];
		if(s!=0 and not (tin <= t and t <= tout)){
			return c.back();
		}
		if(s!=0){
			c.pop_back();
		}
		for(int i=0; i<c.size(); i++){
			tin = (i-1>=0 ? c[i-1] : s), tout = c[i];
			if(tin < t and t <= tout){
				return c[i];
			}
		}
	}
	assert(false);
}

Compilation message

stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:44:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   44 |   for(int i=1; i<c.size(); i++){
      |                ~^~~~~~~~~
stations.cpp:45:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |    tin = c[i], tout = (i+1 < c.size() ? c[i+1] : s);
      |                        ~~~~^~~~~~~~~~
stations.cpp:60:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   60 |   for(int i=0; i<c.size(); i++){
      |                ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 257 ms 940 KB Output is correct
2 Correct 252 ms 940 KB Output is correct
3 Correct 487 ms 684 KB Output is correct
4 Correct 370 ms 684 KB Output is correct
5 Correct 343 ms 684 KB Output is correct
6 Correct 248 ms 940 KB Output is correct
7 Correct 256 ms 684 KB Output is correct
8 Correct 1 ms 768 KB Output is correct
9 Correct 2 ms 768 KB Output is correct
10 Correct 0 ms 776 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 257 ms 940 KB Output is correct
2 Correct 287 ms 684 KB Output is correct
3 Correct 491 ms 684 KB Output is correct
4 Correct 399 ms 684 KB Output is correct
5 Correct 366 ms 684 KB Output is correct
6 Correct 274 ms 684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 251 ms 940 KB Output is correct
2 Correct 293 ms 940 KB Output is correct
3 Correct 559 ms 684 KB Output is correct
4 Correct 388 ms 684 KB Output is correct
5 Correct 322 ms 684 KB Output is correct
6 Correct 261 ms 940 KB Output is correct
7 Correct 258 ms 684 KB Output is correct
8 Correct 0 ms 768 KB Output is correct
9 Correct 1 ms 768 KB Output is correct
10 Correct 0 ms 768 KB Output is correct
11 Correct 377 ms 784 KB Output is correct
12 Correct 273 ms 1012 KB Output is correct
13 Correct 224 ms 1020 KB Output is correct
14 Correct 259 ms 684 KB Output is correct
15 Correct 20 ms 768 KB Output is correct
16 Correct 31 ms 768 KB Output is correct
17 Correct 54 ms 764 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 490 ms 684 KB Output is correct
2 Correct 380 ms 684 KB Output is correct
3 Correct 318 ms 684 KB Output is correct
4 Correct 1 ms 944 KB Output is correct
5 Correct 1 ms 768 KB Output is correct
6 Correct 0 ms 768 KB Output is correct
7 Correct 328 ms 772 KB Output is correct
8 Correct 504 ms 684 KB Output is correct
9 Correct 417 ms 684 KB Output is correct
10 Correct 341 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 1 ms 768 KB Output is correct
14 Correct 1 ms 776 KB Output is correct
15 Correct 1 ms 764 KB Output is correct
16 Correct 297 ms 684 KB Output is correct
17 Correct 317 ms 684 KB Output is correct
18 Correct 302 ms 684 KB Output is correct
19 Correct 284 ms 684 KB Output is correct
20 Correct 267 ms 684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 280 ms 940 KB Output is correct
2 Correct 247 ms 984 KB Output is correct
3 Correct 521 ms 684 KB Output is correct
4 Correct 402 ms 696 KB Output is correct
5 Correct 337 ms 684 KB Output is correct
6 Correct 261 ms 944 KB Output is correct
7 Correct 247 ms 684 KB Output is correct
8 Correct 1 ms 764 KB Output is correct
9 Correct 2 ms 768 KB Output is correct
10 Correct 0 ms 768 KB Output is correct
11 Correct 233 ms 772 KB Output is correct
12 Correct 304 ms 684 KB Output is correct
13 Correct 486 ms 940 KB Output is correct
14 Correct 387 ms 684 KB Output is correct
15 Correct 325 ms 684 KB Output is correct
16 Correct 247 ms 684 KB Output is correct
17 Correct 342 ms 684 KB Output is correct
18 Correct 242 ms 1184 KB Output is correct
19 Correct 285 ms 1012 KB Output is correct
20 Correct 272 ms 684 KB Output is correct
21 Correct 22 ms 768 KB Output is correct
22 Correct 46 ms 768 KB Output is correct
23 Correct 67 ms 760 KB Output is correct
24 Correct 2 ms 768 KB Output is correct
25 Correct 2 ms 768 KB Output is correct
26 Correct 1 ms 768 KB Output is correct
27 Correct 1 ms 768 KB Output is correct
28 Correct 0 ms 768 KB Output is correct
29 Correct 284 ms 684 KB Output is correct
30 Correct 300 ms 684 KB Output is correct
31 Correct 271 ms 684 KB Output is correct
32 Correct 332 ms 684 KB Output is correct
33 Correct 323 ms 684 KB Output is correct
34 Correct 195 ms 940 KB Output is correct
35 Correct 231 ms 940 KB Output is correct
36 Correct 237 ms 1188 KB Output is correct
37 Correct 264 ms 1020 KB Output is correct
38 Correct 273 ms 680 KB Output is correct
39 Correct 253 ms 936 KB Output is correct
40 Correct 270 ms 768 KB Output is correct
41 Correct 243 ms 1024 KB Output is correct
42 Correct 26 ms 764 KB Output is correct
43 Correct 60 ms 712 KB Output is correct
44 Correct 50 ms 684 KB Output is correct
45 Correct 73 ms 684 KB Output is correct
46 Correct 183 ms 768 KB Output is correct
47 Correct 167 ms 684 KB Output is correct
48 Correct 26 ms 940 KB Output is correct
49 Correct 24 ms 844 KB Output is correct