Submission #990267

# Submission time Handle Problem Language Result Execution time Memory
990267 2024-05-30T04:28:44 Z PoPularPlusPlus Stations (IOI20_stations) C++17
100 / 100
677 ms 1308 KB
#include "stations.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) x.begin(),x.end()
#define vf first 
#define vs second

const int N = 1003;

vector<int> adj[N]; 
int col[N],tin[N] , tout[N] , timer;

void dfs(int node ,int par ,int c){
	col[node] = c;
	int c_next = (c + 1)%2;
	tin[node] = timer++;

	for(int i : adj[node]){
		if(i != par){
			dfs(i , node , c_next);
		}
	}

	tout[node] = timer++;
}

vector<int> label(int n, int k, vector<int> u, vector<int> v){

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

	vector<int> labels(n);
	for(int i = 0; i < n; i++){
		if(col[i] == 0)labels[i] = tin[i];
		else labels[i] = tout[i];
	}

	map<int,int> m;
	for(int i = 0; i < n; i++){
		m[labels[i]] = 1;
	}

	int val[2 * n + 5];
	int cur = 0;
	for(auto i : m){
		val[i.vf] = cur++;
	}

	for(int i = 0; i < n; i++){
		labels[i] = val[labels[i]];
		//cout << labels[i] << ' ';
	}

	for(int i = 0; i <= n; i++){
		adj[i].clear();
	}
	
	return labels;
}

int find_next_station(int s, int t, vector<int> c) {
	sort(all(c));
	if(s == 0){
		int prev = 0;
		for(int i : c){
			if(t >= prev && t <= i){
				return i;
			}
		}
	}
	else {
		int col;
		if(c[0] > s){
			col = 0;
		}
		else col = 1;
		int par;
		if(col == 0){
			par = c.back();
		}
		else par = c[0];

		if(col == 0){
			int prev = s;
			for(int i = 0; i < c.size()-1; i++){
				if(t >= s && t <= c[i]){
					return c[i];
				}
				prev = c[i] + 1;
			}
			return par;
		}
		else {
			for(int i = 1; i < c.size()-1; i++){
				if(t >= c[i] && t < c[i + 1]){
					return c[i];
				}
			}
			if(t >= c.back() && t <= s){
				return c.back();
			}
			return par;
		}
	}
}

Compilation message

stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:92:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   92 |    for(int i = 0; i < c.size()-1; i++){
      |                   ~~^~~~~~~~~~~~
stations.cpp:91:8: warning: variable 'prev' set but not used [-Wunused-but-set-variable]
   91 |    int prev = s;
      |        ^~~~
stations.cpp:101:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  101 |    for(int i = 1; i < c.size()-1; i++){
      |                   ~~^~~~~~~~~~~~
stations.cpp:112:1: warning: control reaches end of non-void function [-Wreturn-type]
  112 | }
      | ^
# Verdict Execution time Memory Grader output
1 Correct 365 ms 940 KB Output is correct
2 Correct 307 ms 940 KB Output is correct
3 Correct 631 ms 684 KB Output is correct
4 Correct 441 ms 688 KB Output is correct
5 Correct 419 ms 684 KB Output is correct
6 Correct 309 ms 1208 KB Output is correct
7 Correct 344 ms 940 KB Output is correct
8 Correct 2 ms 768 KB Output is correct
9 Correct 3 ms 776 KB Output is correct
10 Correct 0 ms 776 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 293 ms 684 KB Output is correct
2 Correct 374 ms 684 KB Output is correct
3 Correct 635 ms 684 KB Output is correct
4 Correct 481 ms 684 KB Output is correct
5 Correct 425 ms 684 KB Output is correct
6 Correct 298 ms 684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 391 ms 940 KB Output is correct
2 Correct 306 ms 940 KB Output is correct
3 Correct 588 ms 684 KB Output is correct
4 Correct 467 ms 684 KB Output is correct
5 Correct 430 ms 684 KB Output is correct
6 Correct 297 ms 940 KB Output is correct
7 Correct 310 ms 940 KB Output is correct
8 Correct 2 ms 764 KB Output is correct
9 Correct 1 ms 768 KB Output is correct
10 Correct 0 ms 768 KB Output is correct
11 Correct 430 ms 800 KB Output is correct
12 Correct 306 ms 1044 KB Output is correct
13 Correct 364 ms 1192 KB Output is correct
14 Correct 308 ms 684 KB Output is correct
15 Correct 40 ms 776 KB Output is correct
16 Correct 40 ms 768 KB Output is correct
17 Correct 58 ms 712 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 615 ms 684 KB Output is correct
2 Correct 419 ms 684 KB Output is correct
3 Correct 411 ms 684 KB Output is correct
4 Correct 1 ms 768 KB Output is correct
5 Correct 1 ms 1028 KB Output is correct
6 Correct 1 ms 768 KB Output is correct
7 Correct 390 ms 684 KB Output is correct
8 Correct 640 ms 684 KB Output is correct
9 Correct 439 ms 684 KB Output is correct
10 Correct 401 ms 684 KB Output is correct
11 Correct 2 ms 768 KB Output is correct
12 Correct 4 ms 768 KB Output is correct
13 Correct 2 ms 768 KB Output is correct
14 Correct 1 ms 776 KB Output is correct
15 Correct 0 ms 768 KB Output is correct
16 Correct 317 ms 684 KB Output is correct
17 Correct 351 ms 684 KB Output is correct
18 Correct 328 ms 684 KB Output is correct
19 Correct 338 ms 684 KB Output is correct
20 Correct 337 ms 684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 341 ms 940 KB Output is correct
2 Correct 306 ms 940 KB Output is correct
3 Correct 637 ms 688 KB Output is correct
4 Correct 414 ms 684 KB Output is correct
5 Correct 413 ms 684 KB Output is correct
6 Correct 322 ms 972 KB Output is correct
7 Correct 295 ms 684 KB Output is correct
8 Correct 1 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 321 ms 684 KB Output is correct
12 Correct 352 ms 684 KB Output is correct
13 Correct 677 ms 684 KB Output is correct
14 Correct 455 ms 684 KB Output is correct
15 Correct 412 ms 684 KB Output is correct
16 Correct 300 ms 684 KB Output is correct
17 Correct 421 ms 684 KB Output is correct
18 Correct 308 ms 940 KB Output is correct
19 Correct 330 ms 940 KB Output is correct
20 Correct 290 ms 684 KB Output is correct
21 Correct 30 ms 760 KB Output is correct
22 Correct 38 ms 768 KB Output is correct
23 Correct 71 ms 716 KB Output is correct
24 Correct 2 ms 772 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 768 KB Output is correct
28 Correct 0 ms 768 KB Output is correct
29 Correct 356 ms 800 KB Output is correct
30 Correct 318 ms 712 KB Output is correct
31 Correct 338 ms 684 KB Output is correct
32 Correct 337 ms 688 KB Output is correct
33 Correct 320 ms 684 KB Output is correct
34 Correct 207 ms 940 KB Output is correct
35 Correct 287 ms 940 KB Output is correct
36 Correct 281 ms 940 KB Output is correct
37 Correct 340 ms 1196 KB Output is correct
38 Correct 337 ms 940 KB Output is correct
39 Correct 317 ms 1304 KB Output is correct
40 Correct 298 ms 1188 KB Output is correct
41 Correct 310 ms 1308 KB Output is correct
42 Correct 33 ms 688 KB Output is correct
43 Correct 60 ms 728 KB Output is correct
44 Correct 74 ms 764 KB Output is correct
45 Correct 99 ms 940 KB Output is correct
46 Correct 211 ms 684 KB Output is correct
47 Correct 190 ms 684 KB Output is correct
48 Correct 30 ms 1280 KB Output is correct
49 Correct 28 ms 972 KB Output is correct