답안 #1072157

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1072157 2024-08-23T15:03:53 Z hasan2006 기지국 (IOI20_stations) C++17
100 / 100
666 ms 1408 KB
#include <bits/stdc++.h>
#include "stations.h"
#include <vector>
 
using namespace std;
 
const int maxn = 1e3+10;
 
static int st[maxn], en[maxn], nivel[maxn], tt;
 
vector<int> grafo[maxn];
 
void dfs(int u, int p){
	st[u] = ++tt;
	for (auto v: grafo[u]){
		if (v == p) continue;
		nivel[v] = nivel[u]+1; 
		dfs(v, u);
	}
	en[u] = ++tt;
}
 
vector<int> label(int n, int k, vector<int> u, vector<int> v){
	tt = -1;
	for (int i = 0; i < n; i++)
		grafo[i].clear();
	for (int i = 0; i < n-1; i++){
		grafo[u[i]].push_back(v[i]);
		grafo[v[i]].push_back(u[i]);
	}
	dfs(0, -1);
	vector<int> num;
	for (int i = 0; i < n; i++){
		if (nivel[i]%2 == 0) num.push_back(st[i]);
		else num.push_back(en[i]);
	}
	map<int, int> mp;
	for (auto x: num)
		mp[x] = 0;
	int aux = 0;
	for (auto &x: mp)
		x.second = ++aux;
	for (auto &x: num)
		x = mp[x];
	return num;
}
 
int find_next_station(int u, int v, vector<int> c){
	if (c.size() == 1) return c[0];
	bool flag = 0;
	for (auto x: c)
		if (u < x)
			flag = 1;
	if (!flag){
		for (int i = 1; i < c.size()-1; i++){
			st[i] = c[i];
			en[i] = c[i+1]-1;
		}
 
		st[c.size()-1] = c[c.size()-1];
		en[c.size()-1] = u;
 
		for (int i = 1; i < c.size(); i++)
			if (v >= st[i] && v <= en[i])
				return c[i];
 
		return c[0];
	}else{
		st[0] = u+1;
		en[0] = c[0];
		for (int i = 1; i < c.size()-1; i++){
            en[i] = c[i];
			st[i] = en[i-1]+1;
		}
 
		for (int i = 0; i < c.size()-1; i++)
			if (v >= st[i] && v <= en[i])
				return c[i];
 
		return c[c.size()-1];
	}
}

Compilation message

stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:55:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |   for (int i = 1; i < c.size()-1; i++){
      |                   ~~^~~~~~~~~~~~
stations.cpp:63:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   63 |   for (int i = 1; i < c.size(); i++)
      |                   ~~^~~~~~~~~~
stations.cpp:71:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   71 |   for (int i = 1; i < c.size()-1; i++){
      |                   ~~^~~~~~~~~~~~
stations.cpp:76:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   76 |   for (int i = 0; i < c.size()-1; i++)
      |                   ~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 384 ms 940 KB Output is correct
2 Correct 283 ms 940 KB Output is correct
3 Correct 615 ms 684 KB Output is correct
4 Correct 494 ms 684 KB Output is correct
5 Correct 442 ms 684 KB Output is correct
6 Correct 332 ms 944 KB Output is correct
7 Correct 311 ms 940 KB Output is correct
8 Correct 1 ms 768 KB Output is correct
9 Correct 1 ms 776 KB Output is correct
10 Correct 0 ms 768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 348 ms 684 KB Output is correct
2 Correct 378 ms 684 KB Output is correct
3 Correct 624 ms 684 KB Output is correct
4 Correct 443 ms 684 KB Output is correct
5 Correct 411 ms 684 KB Output is correct
6 Correct 349 ms 684 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 382 ms 940 KB Output is correct
2 Correct 310 ms 940 KB Output is correct
3 Correct 666 ms 684 KB Output is correct
4 Correct 492 ms 684 KB Output is correct
5 Correct 422 ms 684 KB Output is correct
6 Correct 312 ms 944 KB Output is correct
7 Correct 266 ms 940 KB Output is correct
8 Correct 1 ms 776 KB Output is correct
9 Correct 2 ms 768 KB Output is correct
10 Correct 0 ms 764 KB Output is correct
11 Correct 395 ms 684 KB Output is correct
12 Correct 316 ms 1056 KB Output is correct
13 Correct 315 ms 1052 KB Output is correct
14 Correct 319 ms 684 KB Output is correct
15 Correct 24 ms 764 KB Output is correct
16 Correct 34 ms 768 KB Output is correct
17 Correct 69 ms 768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 621 ms 684 KB Output is correct
2 Correct 493 ms 684 KB Output is correct
3 Correct 428 ms 684 KB Output is correct
4 Correct 1 ms 776 KB Output is correct
5 Correct 3 ms 768 KB Output is correct
6 Correct 1 ms 776 KB Output is correct
7 Correct 414 ms 684 KB Output is correct
8 Correct 630 ms 684 KB Output is correct
9 Correct 462 ms 684 KB Output is correct
10 Correct 385 ms 684 KB Output is correct
11 Correct 3 ms 780 KB Output is correct
12 Correct 4 ms 768 KB Output is correct
13 Correct 2 ms 764 KB Output is correct
14 Correct 3 ms 768 KB Output is correct
15 Correct 0 ms 776 KB Output is correct
16 Correct 386 ms 684 KB Output is correct
17 Correct 321 ms 684 KB Output is correct
18 Correct 321 ms 684 KB Output is correct
19 Correct 308 ms 684 KB Output is correct
20 Correct 306 ms 684 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 355 ms 1192 KB Output is correct
2 Correct 298 ms 940 KB Output is correct
3 Correct 642 ms 688 KB Output is correct
4 Correct 482 ms 684 KB Output is correct
5 Correct 406 ms 684 KB Output is correct
6 Correct 303 ms 940 KB Output is correct
7 Correct 303 ms 940 KB Output is correct
8 Correct 2 ms 776 KB Output is correct
9 Correct 2 ms 776 KB Output is correct
10 Correct 0 ms 776 KB Output is correct
11 Correct 292 ms 684 KB Output is correct
12 Correct 367 ms 684 KB Output is correct
13 Correct 509 ms 688 KB Output is correct
14 Correct 372 ms 684 KB Output is correct
15 Correct 333 ms 792 KB Output is correct
16 Correct 272 ms 684 KB Output is correct
17 Correct 380 ms 684 KB Output is correct
18 Correct 281 ms 1196 KB Output is correct
19 Correct 321 ms 1052 KB Output is correct
20 Correct 289 ms 684 KB Output is correct
21 Correct 35 ms 760 KB Output is correct
22 Correct 35 ms 768 KB Output is correct
23 Correct 62 ms 744 KB Output is correct
24 Correct 2 ms 764 KB Output is correct
25 Correct 3 ms 764 KB Output is correct
26 Correct 1 ms 776 KB Output is correct
27 Correct 1 ms 776 KB Output is correct
28 Correct 0 ms 776 KB Output is correct
29 Correct 350 ms 684 KB Output is correct
30 Correct 349 ms 684 KB Output is correct
31 Correct 360 ms 684 KB Output is correct
32 Correct 313 ms 684 KB Output is correct
33 Correct 345 ms 684 KB Output is correct
34 Correct 234 ms 940 KB Output is correct
35 Correct 266 ms 1052 KB Output is correct
36 Correct 284 ms 1052 KB Output is correct
37 Correct 283 ms 1200 KB Output is correct
38 Correct 250 ms 1060 KB Output is correct
39 Correct 284 ms 1068 KB Output is correct
40 Correct 264 ms 1196 KB Output is correct
41 Correct 255 ms 1064 KB Output is correct
42 Correct 34 ms 684 KB Output is correct
43 Correct 63 ms 940 KB Output is correct
44 Correct 76 ms 684 KB Output is correct
45 Correct 91 ms 684 KB Output is correct
46 Correct 177 ms 684 KB Output is correct
47 Correct 189 ms 684 KB Output is correct
48 Correct 38 ms 1112 KB Output is correct
49 Correct 32 ms 1408 KB Output is correct