답안 #1032306

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1032306 2024-07-23T15:30:28 Z 0npata 즐거운 행로 (APIO20_fun) C++17
26 / 100
21 ms 504 KB
#include "fun.h"

#include<bits/stdc++.h>
using namespace std;

#define vec vector

const int MXN = 505;

vec<int> tree[MXN];
int depth[MXN];

void dfs1(int u, int p = -1) {
	for(int v : tree[u]) {
		if(v == p) continue;
		depth[v] = depth[u]+1;
		dfs1(v, u);
	}
}


std::vector<int> createFunTour(int N, int Q) {
	if(N>500) {
		vec<int> ans(0);
		for(int i = N-1; i>=0; i--) {
			ans.push_back(i);
		}
		return ans;
	}


	for(int i = 0; i<N; i++) {
		for(int j = 0; j<N; j++) {
			if(i == j) {
				continue;
			}
			if(hoursRequired(i, j) == 1) {
				tree[i].push_back(j);
			}
		}
	}
	set<int> used;
	auto comp_depth = [&](int u) {
		depth[u] = 0;
		dfs1(u);
	};

	comp_depth(0);

	int x = 0;
	for(int i = 0; i<N; i++) {
		if(depth[i] > depth[x]) x = i;
	}

	vec<int> ans(0);

	for(int i = 0; i<N; i++) {
		comp_depth(x);
		for(int i = 0; i<N; i++) {
			if(!used.count(i) && depth[i] > depth[x]) x = i;
		}

		ans.push_back(x);
		used.insert(x);
	}
	assert(used.size() == N);

	return ans;
}

Compilation message

In file included from /usr/include/c++/10/cassert:44,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:33,
                 from fun.cpp:3:
fun.cpp: In function 'std::vector<int> createFunTour(int, int)':
fun.cpp:66:21: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   66 |  assert(used.size() == N);
      |         ~~~~~~~~~~~~^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 392 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 392 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 13 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 14 ms 344 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 3 ms 348 KB Output is correct
32 Correct 4 ms 348 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 13 ms 344 KB Output is correct
35 Correct 19 ms 348 KB Output is correct
36 Correct 21 ms 504 KB Output is correct
37 Correct 1 ms 348 KB Output is correct
38 Correct 17 ms 348 KB Output is correct
39 Correct 6 ms 348 KB Output is correct
40 Correct 8 ms 348 KB Output is correct
41 Correct 3 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 392 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 13 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Incorrect 1 ms 348 KB Tour is not fun
17 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 14 ms 344 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 3 ms 348 KB Output is correct
11 Correct 4 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Incorrect 1 ms 348 KB Tour is not fun
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 392 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 13 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 14 ms 344 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 3 ms 348 KB Output is correct
32 Correct 4 ms 348 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 13 ms 344 KB Output is correct
35 Correct 19 ms 348 KB Output is correct
36 Correct 21 ms 504 KB Output is correct
37 Correct 1 ms 348 KB Output is correct
38 Correct 17 ms 348 KB Output is correct
39 Correct 6 ms 348 KB Output is correct
40 Correct 8 ms 348 KB Output is correct
41 Correct 3 ms 344 KB Output is correct
42 Incorrect 1 ms 348 KB Tour is not fun
43 Halted 0 ms 0 KB -