답안 #321512

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
321512 2020-11-12T15:35:43 Z NachoLibre 기지국 (IOI20_stations) C++14
100 / 100
1124 ms 1280 KB
#include <bits/stdc++.h>
using namespace std;

const int N = 1003;
vector<int> v[N], dr;
int tn;

void sgd(int dg, int op, int dt) {
	if(dt & 1 ^ 1) dr[dg] = tn, ++tn;
	for(int i = 0; i < v[dg].size(); ++i) {
		if(v[dg][i] != op) {
			sgd(v[dg][i], dg, dt + 1);
		}
	}
	if(dt & 1) dr[dg] = tn, ++tn;
}

vector<int> label(int n, int k, vector<int> x, vector<int> y) {
	for(int i = 0; i < n; ++i) v[i].clear();
	for(int i = 0; i < n - 1; ++i) {
		v[x[i]].push_back(y[i]);
		v[y[i]].push_back(x[i]);
	}
	dr.clear();
	for(int i = 0; i < n; ++i) dr.push_back(0);
	tn = 0;
	sgd(0, -1, 0);
	return dr;
}

int find_next_station(int a, int b, vector<int> v) {
	int n = v.size();
	if(a == 0) {
		sort(v.begin(), v.end());
		for(int i = 0; i < n; ++i) {
			if(b <= v[i]) return v[i];
		}
		assert(0);
	} else if(v[0] > a) {
		sort(v.begin(), v.end());
		if(b < a) return v[n - 1];
		for(int i = 0; i < n - 1; ++i) {
			if(b <= v[i]) return v[i];
		}
		return v[n - 1];
	} else {
		if(n == 1) return v[0];
		sort(v.begin(), v.end());
		v.push_back(v[0]);
		for(int i = 0; i < n; ++i) v[i] = v[i + 1];
		v.pop_back();
		if(b < v[0]) return v[n - 1];
		if(b > a) return v[n - 1];
		for(int i = 1; i < n - 1; ++i) {
			if(b < v[i]) return v[i - 1];
		}
		return v[n - 2];
	}
}

////////////
//
// vector<int> ve[N], xv, yv;
//
// void add(int a, int b) {
// 	xv.push_back(a);
// 	yv.push_back(b);
// 	ve[a].push_back(b);
// 	ve[b].push_back(a);
// }
//
// vector<int> drv(vector<int> v) {
// 	for(int i = 0; i < v.size(); ++i) {
// 		v[i] = dr[v[i]];
// 	}
// 	return v;
// }
//
// int dwb, dwm;
// void sgd(int dg, int op) {
// 	cout << dwb << " > " << dg << " = " << find_next_station(dr[dwb], dr[dg], drv(ve[dwb])) << " --> " << dr[dwm] << endl;
// 	for(int i = 0; i < ve[dg].size(); ++i) {
// 		if(ve[dg][i] != op) {
// 			sgd(ve[dg][i], dg);
// 		}
// 	}
// }
//
// int main() {
// 	ios::sync_with_stdio(0);
// 	cin.tie(0);
// 	int n = 5;
// 	add(0, 1);
// 	add(0, 2);
// 	add(1, 3);
// 	add(1, 4);
// 	dr = label(n, n, xv, yv);
// 	for(dwb = 0; dwb < n; ++dwb) {
// 		for(int i = 0; i < ve[dwb].size(); ++i) {
// 			dwm = ve[dwb][i];
// 			sgd(dwm, dwb);
// 		}
// 	}
// 	return 0;
// 	dr = label(5, 4, {0, 1, 1, 2}, {1, 2, 3, 4});
// 	cout << find_next_station(dr[2], dr[0], {dr[1], dr[4]}) << " --> " << dr[1] << endl;
// 	cout << find_next_station(dr[1], dr[3], {dr[3], dr[2], dr[0]}) << " --> " << dr[3] << endl;
// 	cout << find_next_station(dr[4], dr[3], {dr[2]}) << " --> " << dr[2] << endl;
// 	return 0;
// }

Compilation message

stations.cpp: In function 'void sgd(int, int, int)':
stations.cpp:9:8: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
    9 |  if(dt & 1 ^ 1) dr[dg] = tn, ++tn;
      |     ~~~^~~
stations.cpp:10:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   10 |  for(int i = 0; i < v[dg].size(); ++i) {
      |                 ~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 595 ms 1260 KB Output is correct
2 Correct 545 ms 996 KB Output is correct
3 Correct 972 ms 864 KB Output is correct
4 Correct 690 ms 1024 KB Output is correct
5 Correct 682 ms 864 KB Output is correct
6 Correct 601 ms 992 KB Output is correct
7 Correct 457 ms 992 KB Output is correct
8 Correct 34 ms 960 KB Output is correct
9 Correct 36 ms 864 KB Output is correct
10 Correct 54 ms 972 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 516 ms 864 KB Output is correct
2 Correct 625 ms 992 KB Output is correct
3 Correct 1124 ms 1108 KB Output is correct
4 Correct 713 ms 824 KB Output is correct
5 Correct 719 ms 992 KB Output is correct
6 Correct 540 ms 1020 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 618 ms 1072 KB Output is correct
2 Correct 494 ms 864 KB Output is correct
3 Correct 1019 ms 884 KB Output is correct
4 Correct 715 ms 736 KB Output is correct
5 Correct 699 ms 952 KB Output is correct
6 Correct 509 ms 1200 KB Output is correct
7 Correct 489 ms 1012 KB Output is correct
8 Correct 2 ms 864 KB Output is correct
9 Correct 110 ms 992 KB Output is correct
10 Correct 2 ms 816 KB Output is correct
11 Correct 660 ms 768 KB Output is correct
12 Correct 530 ms 1200 KB Output is correct
13 Correct 653 ms 1008 KB Output is correct
14 Correct 509 ms 896 KB Output is correct
15 Correct 117 ms 736 KB Output is correct
16 Correct 70 ms 992 KB Output is correct
17 Correct 129 ms 888 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 941 ms 864 KB Output is correct
2 Correct 786 ms 864 KB Output is correct
3 Correct 655 ms 736 KB Output is correct
4 Correct 3 ms 960 KB Output is correct
5 Correct 4 ms 960 KB Output is correct
6 Correct 2 ms 736 KB Output is correct
7 Correct 603 ms 992 KB Output is correct
8 Correct 918 ms 864 KB Output is correct
9 Correct 704 ms 992 KB Output is correct
10 Correct 727 ms 952 KB Output is correct
11 Correct 7 ms 864 KB Output is correct
12 Correct 7 ms 992 KB Output is correct
13 Correct 4 ms 864 KB Output is correct
14 Correct 3 ms 864 KB Output is correct
15 Correct 2 ms 960 KB Output is correct
16 Correct 632 ms 736 KB Output is correct
17 Correct 565 ms 1080 KB Output is correct
18 Correct 567 ms 960 KB Output is correct
19 Correct 611 ms 736 KB Output is correct
20 Correct 607 ms 992 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 601 ms 992 KB Output is correct
2 Correct 459 ms 864 KB Output is correct
3 Correct 941 ms 952 KB Output is correct
4 Correct 743 ms 952 KB Output is correct
5 Correct 605 ms 1088 KB Output is correct
6 Correct 439 ms 1072 KB Output is correct
7 Correct 501 ms 1112 KB Output is correct
8 Correct 3 ms 952 KB Output is correct
9 Correct 4 ms 992 KB Output is correct
10 Correct 2 ms 864 KB Output is correct
11 Correct 480 ms 736 KB Output is correct
12 Correct 697 ms 1024 KB Output is correct
13 Correct 979 ms 864 KB Output is correct
14 Correct 770 ms 864 KB Output is correct
15 Correct 683 ms 1120 KB Output is correct
16 Correct 473 ms 896 KB Output is correct
17 Correct 612 ms 1108 KB Output is correct
18 Correct 550 ms 1120 KB Output is correct
19 Correct 479 ms 1280 KB Output is correct
20 Correct 435 ms 736 KB Output is correct
21 Correct 60 ms 864 KB Output is correct
22 Correct 81 ms 992 KB Output is correct
23 Correct 99 ms 880 KB Output is correct
24 Correct 6 ms 864 KB Output is correct
25 Correct 6 ms 864 KB Output is correct
26 Correct 5 ms 736 KB Output is correct
27 Correct 4 ms 864 KB Output is correct
28 Correct 2 ms 736 KB Output is correct
29 Correct 585 ms 992 KB Output is correct
30 Correct 617 ms 952 KB Output is correct
31 Correct 615 ms 736 KB Output is correct
32 Correct 574 ms 952 KB Output is correct
33 Correct 576 ms 960 KB Output is correct
34 Correct 392 ms 1216 KB Output is correct
35 Correct 548 ms 1192 KB Output is correct
36 Correct 477 ms 1000 KB Output is correct
37 Correct 502 ms 1152 KB Output is correct
38 Correct 539 ms 1120 KB Output is correct
39 Correct 592 ms 1116 KB Output is correct
40 Correct 493 ms 1248 KB Output is correct
41 Correct 505 ms 1240 KB Output is correct
42 Correct 74 ms 864 KB Output is correct
43 Correct 133 ms 1016 KB Output is correct
44 Correct 163 ms 864 KB Output is correct
45 Correct 161 ms 736 KB Output is correct
46 Correct 344 ms 736 KB Output is correct
47 Correct 438 ms 864 KB Output is correct
48 Correct 78 ms 1232 KB Output is correct
49 Correct 60 ms 864 KB Output is correct