답안 #940806

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
940806 2024-03-07T16:30:33 Z rainboy Company Planning (TOKI14_company) C
100 / 100
92 ms 10328 KB
#include <stdio.h>
#include <stdlib.h>

#define N	100000

unsigned int X = 12345;

int rand_() {
	return (X *= 3) >> 1;
}

int *ej[N], eo[N];

void append(int i, int j) {
	int o = eo[i]++;

	if (o >= 2 && (o & o - 1) == 0)
		ej[i] = (int *) realloc(ej[i], o * 2 * sizeof *ej[i]);
	ej[i][o] = j;
}

int dp[N], k;

void sort(int *ii, int l, int r) {
	while (l < r) {
		int i = l, j = l, k = r, i_ = ii[l + rand_() % (r - l)], tmp;

		while (j < k)
			if (dp[ii[j]] == dp[i_])
				j++;
			else if (dp[ii[j]] < dp[i_]) {
				tmp = ii[i], ii[i] = ii[j], ii[j] = tmp;
				i++, j++;
			} else {
				k--;
				tmp = ii[j], ii[j] = ii[k], ii[k] = tmp;
			}
		sort(ii, l, i);
		l = k;
	}
}

void dfs(int i) {
	int o;

	for (o = eo[i]; o--; ) {
		int j = ej[i][o];

		dfs(j);
	}
	sort(ej[i], 0, eo[i]);
	dp[i] = 1;
	for (o = eo[i] - 1; o >= 0 && o >= eo[i] - k; o--)
		dp[i] += dp[ej[i][o]];
}

int main() {
	int n, m, i, j, lower, upper;

	scanf("%d%d", &n, &m);
	for (i = 0; i < n; i++)
		ej[i] = (int *) malloc(2 * sizeof *ej[i]);
	for (j = 1; j < n; j++) {
		scanf("%d", &i), i--;
		append(i, j);
	}
	lower = -1, upper = n - 1;
	while (upper - lower > 1) {
		k = (lower + upper) / 2;
		dfs(0);
		if (dp[0] >= m)
			upper = k;
		else
			lower = k;
	}
	printf("%d\n", upper);
	return 0;
}

Compilation message

company.c: In function 'append':
company.c:17:23: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
   17 |  if (o >= 2 && (o & o - 1) == 0)
      |                     ~~^~~
company.c: In function 'main':
company.c:60:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   60 |  scanf("%d%d", &n, &m);
      |  ^~~~~~~~~~~~~~~~~~~~~
company.c:64:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   64 |   scanf("%d", &i), i--;
      |   ^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 432 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 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 756 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 428 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 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 1 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 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 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 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 428 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 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 344 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 Correct 1 ms 348 KB Output is correct
17 Correct 1 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 1 ms 344 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 428 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 352 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 1 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 74 ms 4956 KB Output is correct
3 Correct 24 ms 5468 KB Output is correct
4 Correct 25 ms 5464 KB Output is correct
5 Correct 76 ms 5468 KB Output is correct
6 Correct 64 ms 5212 KB Output is correct
7 Correct 61 ms 5016 KB Output is correct
8 Correct 58 ms 4696 KB Output is correct
9 Correct 64 ms 5148 KB Output is correct
10 Correct 52 ms 4444 KB Output is correct
11 Correct 58 ms 4700 KB Output is correct
12 Correct 73 ms 5600 KB Output is correct
13 Correct 69 ms 5468 KB Output is correct
14 Correct 40 ms 3416 KB Output is correct
15 Correct 80 ms 5148 KB Output is correct
16 Correct 41 ms 3672 KB Output is correct
17 Correct 56 ms 4444 KB Output is correct
18 Correct 29 ms 2648 KB Output is correct
19 Correct 10 ms 2392 KB Output is correct
20 Correct 20 ms 4620 KB Output is correct
21 Correct 15 ms 3416 KB Output is correct
22 Correct 6 ms 1628 KB Output is correct
23 Correct 20 ms 4444 KB Output is correct
24 Correct 22 ms 4956 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 21 ms 5212 KB Output is correct
3 Correct 20 ms 5448 KB Output is correct
4 Correct 35 ms 5668 KB Output is correct
5 Correct 47 ms 5720 KB Output is correct
6 Correct 32 ms 5284 KB Output is correct
7 Correct 40 ms 10176 KB Output is correct
8 Correct 71 ms 5720 KB Output is correct
9 Correct 72 ms 5600 KB Output is correct
10 Correct 57 ms 4696 KB Output is correct
11 Correct 22 ms 2140 KB Output is correct
12 Correct 66 ms 5040 KB Output is correct
13 Correct 45 ms 3672 KB Output is correct
14 Correct 68 ms 5076 KB Output is correct
15 Correct 71 ms 5668 KB Output is correct
16 Correct 34 ms 2908 KB Output is correct
17 Correct 32 ms 2908 KB Output is correct
18 Correct 51 ms 4188 KB Output is correct
19 Correct 58 ms 4444 KB Output is correct
20 Correct 28 ms 2464 KB Output is correct
21 Correct 15 ms 1624 KB Output is correct
22 Correct 16 ms 4760 KB Output is correct
23 Correct 28 ms 6492 KB Output is correct
24 Correct 22 ms 6236 KB Output is correct
25 Correct 17 ms 3140 KB Output is correct
26 Correct 35 ms 4956 KB Output is correct
27 Correct 26 ms 5212 KB Output is correct
28 Correct 20 ms 3416 KB Output is correct
29 Correct 21 ms 4700 KB Output is correct
30 Correct 27 ms 4444 KB Output is correct
31 Correct 28 ms 4664 KB Output is correct
32 Correct 13 ms 1628 KB Output is correct
33 Correct 8 ms 2396 KB Output is correct
34 Correct 9 ms 2652 KB Output is correct
35 Correct 2 ms 856 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 18 ms 5212 KB Output is correct
3 Correct 19 ms 5212 KB Output is correct
4 Correct 36 ms 5492 KB Output is correct
5 Correct 38 ms 5468 KB Output is correct
6 Correct 33 ms 5464 KB Output is correct
7 Correct 54 ms 10308 KB Output is correct
8 Correct 73 ms 5724 KB Output is correct
9 Correct 23 ms 5468 KB Output is correct
10 Correct 21 ms 5212 KB Output is correct
11 Correct 43 ms 5656 KB Output is correct
12 Correct 38 ms 5468 KB Output is correct
13 Correct 29 ms 5456 KB Output is correct
14 Correct 43 ms 10328 KB Output is correct
15 Correct 74 ms 5720 KB Output is correct
16 Correct 92 ms 5468 KB Output is correct
17 Correct 78 ms 5468 KB Output is correct
18 Correct 70 ms 5464 KB Output is correct
19 Correct 55 ms 4576 KB Output is correct
20 Correct 51 ms 4148 KB Output is correct
21 Correct 62 ms 4424 KB Output is correct
22 Correct 14 ms 1624 KB Output is correct
23 Correct 50 ms 4196 KB Output is correct
24 Correct 20 ms 2140 KB Output is correct
25 Correct 30 ms 2652 KB Output is correct
26 Correct 32 ms 2960 KB Output is correct
27 Correct 66 ms 4868 KB Output is correct
28 Correct 79 ms 5160 KB Output is correct
29 Correct 68 ms 5292 KB Output is correct
30 Correct 6 ms 860 KB Output is correct
31 Correct 14 ms 1372 KB Output is correct
32 Correct 70 ms 5376 KB Output is correct
33 Correct 64 ms 5020 KB Output is correct
34 Correct 14 ms 1628 KB Output is correct
35 Correct 68 ms 5208 KB Output is correct
36 Correct 74 ms 5468 KB Output is correct
37 Correct 57 ms 4440 KB Output is correct
38 Correct 53 ms 3920 KB Output is correct
39 Correct 70 ms 5468 KB Output is correct
40 Correct 5 ms 856 KB Output is correct
41 Correct 29 ms 2652 KB Output is correct
42 Correct 32 ms 8540 KB Output is correct
43 Correct 20 ms 4188 KB Output is correct
44 Correct 25 ms 6696 KB Output is correct
45 Correct 39 ms 4952 KB Output is correct
46 Correct 8 ms 1880 KB Output is correct
47 Correct 33 ms 7260 KB Output is correct
48 Correct 35 ms 8792 KB Output is correct
49 Correct 44 ms 9820 KB Output is correct
50 Correct 34 ms 5212 KB Output is correct
51 Correct 18 ms 3164 KB Output is correct
52 Correct 18 ms 4052 KB Output is correct
53 Correct 20 ms 4444 KB Output is correct
54 Correct 11 ms 2704 KB Output is correct
55 Correct 26 ms 4216 KB Output is correct
56 Correct 20 ms 3452 KB Output is correct
57 Correct 56 ms 4676 KB Output is correct
58 Correct 11 ms 2652 KB Output is correct
59 Correct 14 ms 2924 KB Output is correct
60 Correct 21 ms 4692 KB Output is correct
61 Correct 12 ms 2388 KB Output is correct
62 Correct 20 ms 3416 KB Output is correct
63 Correct 30 ms 2648 KB Output is correct
64 Correct 17 ms 4436 KB Output is correct
65 Correct 20 ms 4692 KB Output is correct
66 Correct 10 ms 3164 KB Output is correct
67 Correct 9 ms 2648 KB Output is correct
68 Correct 15 ms 4436 KB Output is correct
69 Correct 8 ms 2652 KB Output is correct
70 Correct 14 ms 4320 KB Output is correct
71 Correct 9 ms 2904 KB Output is correct
72 Correct 0 ms 344 KB Output is correct