Submission #926801

# Submission time Handle Problem Language Result Execution time Memory
926801 2024-02-13T18:19:26 Z velislavgarkov Stations (IOI20_stations) C++14
100 / 100
523 ms 1480 KB
#include "stations.h"
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
const int MAXN=1e3+10;
struct Number {
	int x;
	int ind;
	bool friend operator < (Number a, Number b) {
		return a.x<b.x;
	}
};
Number num[MAXN];
vector <int> ver[MAXN];
vector <int> ans;
int in[MAXN], out[MAXN], dep[MAXN];
int br;
void dfs(int x, int par) {
	in[x]=br;
	br++;
	for (auto i:ver[x]) {
		if (i==par) continue;
		dep[i]=dep[x]+1;
		dfs(i,x);
	}
	out[x]=br;
	br++;
	if (dep[x]%2==0) num[x].x=in[x];
	else num[x].x=out[x];
}
vector<int> label(int n, int k, vector<int> u, vector<int> v) {
	for (int i=0;i<n;i++) {
		if (!ver[i].empty()) ver[i].clear();
		num[i].ind=i;
	}
	for (int i=0;i<n-1;i++) {
		ver[u[i]].push_back(v[i]);
		ver[v[i]].push_back(u[i]);
	}
	dep[0]=br=0;
	dfs(0,-1);
	sort(num,num+n);
	ans.resize(n);
	for (int i=0;i<n;i++) ans[num[i].ind]=i;
	return ans;
}

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

Compilation message

stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:51:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   51 |   for (int i=0;i<c.size();i++) {
      |                ~^~~~~~~~~
stations.cpp:57:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   57 |   for (int i=0;i<c.size()-1;i++) {
      |                ~^~~~~~~~~~~
stations.cpp:64:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   64 |   for (int i=1;i<c.size();i++) {
      |                ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 333 ms 944 KB Output is correct
2 Correct 236 ms 940 KB Output is correct
3 Correct 510 ms 684 KB Output is correct
4 Correct 367 ms 684 KB Output is correct
5 Correct 329 ms 684 KB Output is correct
6 Correct 250 ms 936 KB Output is correct
7 Correct 253 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 768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 286 ms 892 KB Output is correct
2 Correct 306 ms 828 KB Output is correct
3 Correct 501 ms 684 KB Output is correct
4 Correct 386 ms 684 KB Output is correct
5 Correct 351 ms 684 KB Output is correct
6 Correct 243 ms 684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 296 ms 940 KB Output is correct
2 Correct 241 ms 948 KB Output is correct
3 Correct 514 ms 684 KB Output is correct
4 Correct 353 ms 684 KB Output is correct
5 Correct 344 ms 684 KB Output is correct
6 Correct 284 ms 944 KB Output is correct
7 Correct 254 ms 684 KB Output is correct
8 Correct 1 ms 768 KB Output is correct
9 Correct 3 ms 768 KB Output is correct
10 Correct 0 ms 768 KB Output is correct
11 Correct 322 ms 684 KB Output is correct
12 Correct 260 ms 1052 KB Output is correct
13 Correct 261 ms 1296 KB Output is correct
14 Correct 246 ms 684 KB Output is correct
15 Correct 28 ms 764 KB Output is correct
16 Correct 35 ms 928 KB Output is correct
17 Correct 52 ms 940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 493 ms 684 KB Output is correct
2 Correct 372 ms 684 KB Output is correct
3 Correct 311 ms 940 KB Output is correct
4 Correct 1 ms 764 KB Output is correct
5 Correct 2 ms 768 KB Output is correct
6 Correct 0 ms 768 KB Output is correct
7 Correct 369 ms 684 KB Output is correct
8 Correct 476 ms 864 KB Output is correct
9 Correct 379 ms 684 KB Output is correct
10 Correct 329 ms 684 KB Output is correct
11 Correct 3 ms 764 KB Output is correct
12 Correct 3 ms 768 KB Output is correct
13 Correct 3 ms 768 KB Output is correct
14 Correct 1 ms 768 KB Output is correct
15 Correct 0 ms 1060 KB Output is correct
16 Correct 290 ms 940 KB Output is correct
17 Correct 286 ms 684 KB Output is correct
18 Correct 282 ms 684 KB Output is correct
19 Correct 262 ms 684 KB Output is correct
20 Correct 284 ms 684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 304 ms 940 KB Output is correct
2 Correct 262 ms 940 KB Output is correct
3 Correct 523 ms 684 KB Output is correct
4 Correct 383 ms 684 KB Output is correct
5 Correct 346 ms 684 KB Output is correct
6 Correct 258 ms 904 KB Output is correct
7 Correct 235 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 1020 KB Output is correct
11 Correct 246 ms 888 KB Output is correct
12 Correct 294 ms 860 KB Output is correct
13 Correct 500 ms 684 KB Output is correct
14 Correct 389 ms 684 KB Output is correct
15 Correct 345 ms 684 KB Output is correct
16 Correct 245 ms 684 KB Output is correct
17 Correct 335 ms 684 KB Output is correct
18 Correct 283 ms 1164 KB Output is correct
19 Correct 262 ms 1440 KB Output is correct
20 Correct 256 ms 944 KB Output is correct
21 Correct 28 ms 1016 KB Output is correct
22 Correct 35 ms 1160 KB Output is correct
23 Correct 52 ms 948 KB Output is correct
24 Correct 2 ms 764 KB Output is correct
25 Correct 3 ms 764 KB Output is correct
26 Correct 3 ms 768 KB Output is correct
27 Correct 1 ms 764 KB Output is correct
28 Correct 1 ms 768 KB Output is correct
29 Correct 288 ms 684 KB Output is correct
30 Correct 272 ms 684 KB Output is correct
31 Correct 272 ms 684 KB Output is correct
32 Correct 288 ms 684 KB Output is correct
33 Correct 279 ms 684 KB Output is correct
34 Correct 175 ms 916 KB Output is correct
35 Correct 246 ms 1348 KB Output is correct
36 Correct 254 ms 1044 KB Output is correct
37 Correct 263 ms 1060 KB Output is correct
38 Correct 258 ms 1424 KB Output is correct
39 Correct 265 ms 1292 KB Output is correct
40 Correct 263 ms 1172 KB Output is correct
41 Correct 257 ms 1032 KB Output is correct
42 Correct 31 ms 940 KB Output is correct
43 Correct 59 ms 1152 KB Output is correct
44 Correct 75 ms 900 KB Output is correct
45 Correct 91 ms 1420 KB Output is correct
46 Correct 172 ms 880 KB Output is correct
47 Correct 153 ms 904 KB Output is correct
48 Correct 33 ms 988 KB Output is correct
49 Correct 35 ms 1480 KB Output is correct