답안 #5867

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
5867 2014-05-20T11:24:37 Z cki86201 Company Planning (TOKI14_company) C++
100 / 100
116 ms 8152 KB
#include<stdio.h>
#include<algorithm>
#include<vector>
using namespace std;

int m, n;
int p[100010], o[100010], q[100010], d[100010];
vector <int> v[100010];

int main()
{
	scanf("%d%d",&n,&m);
	int i;
	for(i=2;i<=n;i++){
		scanf("%d",p+i);
		++o[p[i]];
	}
	int *f = q, *r = q;
	for(i=1;i<=n;i++)if(!o[i])*f++ = i;
	for(i=1;i<=n;i++)d[i] = 1;
	while(f != r){
		int t = *r++;
		if(--o[p[t]] == 0)*f++ = p[t], d[p[t]] += d[t];
	}
	int L = 0, R = n, K = 0;
	while(L <= R){
		int M = (L+R) >> 1;
		for(i=0;i<n;i++){
			int u = q[i], cnt = 1;
			sort(v[u].begin(), v[u].end());
			reverse(v[u].begin(), v[u].end());
			for(int j=0;j<M && j<(int)v[u].size();j++)cnt += v[u][j];
			v[p[u]].push_back(cnt);
			if(i == n-1){
				if(cnt >= m)K = M, R = M-1;
				else L = M+1;
			}
		}
		for(i=1;i<=n;i++)v[i].clear();
	}
	printf("%d",K);
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 5116 KB Output is correct
2 Correct 0 ms 5116 KB Output is correct
3 Correct 0 ms 5116 KB Output is correct
4 Correct 0 ms 5116 KB Output is correct
5 Correct 0 ms 5116 KB Output is correct
6 Correct 0 ms 5116 KB Output is correct
7 Correct 0 ms 5116 KB Output is correct
8 Correct 0 ms 5116 KB Output is correct
9 Correct 0 ms 5116 KB Output is correct
10 Correct 0 ms 5116 KB Output is correct
11 Correct 0 ms 5116 KB Output is correct
12 Correct 0 ms 5116 KB Output is correct
13 Correct 0 ms 5116 KB Output is correct
14 Correct 0 ms 5116 KB Output is correct
15 Correct 0 ms 5116 KB Output is correct
16 Correct 0 ms 5116 KB Output is correct
17 Correct 0 ms 5116 KB Output is correct
18 Correct 0 ms 5116 KB Output is correct
19 Correct 0 ms 5116 KB Output is correct
20 Correct 0 ms 5116 KB Output is correct
21 Correct 0 ms 5116 KB Output is correct
22 Correct 0 ms 5116 KB Output is correct
23 Correct 0 ms 5116 KB Output is correct
24 Correct 0 ms 5116 KB Output is correct
25 Correct 0 ms 5116 KB Output is correct
26 Correct 0 ms 5116 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 5116 KB Output is correct
2 Correct 0 ms 5116 KB Output is correct
3 Correct 0 ms 5116 KB Output is correct
4 Correct 0 ms 5116 KB Output is correct
5 Correct 0 ms 5116 KB Output is correct
6 Correct 0 ms 5116 KB Output is correct
7 Correct 0 ms 5116 KB Output is correct
8 Correct 0 ms 5116 KB Output is correct
9 Correct 0 ms 5116 KB Output is correct
10 Correct 0 ms 5116 KB Output is correct
11 Correct 0 ms 5116 KB Output is correct
12 Correct 0 ms 5116 KB Output is correct
13 Correct 0 ms 5116 KB Output is correct
14 Correct 0 ms 5116 KB Output is correct
15 Correct 0 ms 5116 KB Output is correct
16 Correct 0 ms 5116 KB Output is correct
17 Correct 0 ms 5116 KB Output is correct
18 Correct 0 ms 5116 KB Output is correct
19 Correct 0 ms 5116 KB Output is correct
20 Correct 0 ms 5116 KB Output is correct
21 Correct 0 ms 5116 KB Output is correct
22 Correct 0 ms 5116 KB Output is correct
23 Correct 0 ms 5116 KB Output is correct
24 Correct 0 ms 5116 KB Output is correct
25 Correct 0 ms 5116 KB Output is correct
26 Correct 0 ms 5116 KB Output is correct
27 Correct 0 ms 5116 KB Output is correct
28 Correct 0 ms 5116 KB Output is correct
29 Correct 0 ms 5116 KB Output is correct
30 Correct 0 ms 5116 KB Output is correct
31 Correct 0 ms 5116 KB Output is correct
32 Correct 0 ms 5116 KB Output is correct
33 Correct 0 ms 5116 KB Output is correct
34 Correct 0 ms 5116 KB Output is correct
35 Correct 0 ms 5116 KB Output is correct
36 Correct 0 ms 5116 KB Output is correct
37 Correct 0 ms 5116 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 5116 KB Output is correct
2 Correct 116 ms 7096 KB Output is correct
3 Correct 48 ms 6568 KB Output is correct
4 Correct 48 ms 6568 KB Output is correct
5 Correct 116 ms 7096 KB Output is correct
6 Correct 92 ms 6832 KB Output is correct
7 Correct 96 ms 6832 KB Output is correct
8 Correct 88 ms 6700 KB Output is correct
9 Correct 96 ms 6832 KB Output is correct
10 Correct 68 ms 6568 KB Output is correct
11 Correct 80 ms 6700 KB Output is correct
12 Correct 104 ms 6964 KB Output is correct
13 Correct 108 ms 6964 KB Output is correct
14 Correct 56 ms 6304 KB Output is correct
15 Correct 100 ms 6964 KB Output is correct
16 Correct 60 ms 6304 KB Output is correct
17 Correct 72 ms 6700 KB Output is correct
18 Correct 40 ms 6040 KB Output is correct
19 Correct 20 ms 5644 KB Output is correct
20 Correct 36 ms 6304 KB Output is correct
21 Correct 28 ms 6040 KB Output is correct
22 Correct 12 ms 5512 KB Output is correct
23 Correct 36 ms 6304 KB Output is correct
24 Correct 40 ms 6436 KB Output is correct
25 Correct 0 ms 5116 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 5116 KB Output is correct
2 Correct 52 ms 5692 KB Output is correct
3 Correct 52 ms 5888 KB Output is correct
4 Correct 60 ms 6700 KB Output is correct
5 Correct 88 ms 8020 KB Output is correct
6 Correct 48 ms 6568 KB Output is correct
7 Correct 60 ms 8152 KB Output is correct
8 Correct 100 ms 6832 KB Output is correct
9 Correct 104 ms 6832 KB Output is correct
10 Correct 80 ms 6436 KB Output is correct
11 Correct 28 ms 5644 KB Output is correct
12 Correct 96 ms 6568 KB Output is correct
13 Correct 56 ms 6172 KB Output is correct
14 Correct 96 ms 6568 KB Output is correct
15 Correct 108 ms 6832 KB Output is correct
16 Correct 48 ms 5908 KB Output is correct
17 Correct 40 ms 5908 KB Output is correct
18 Correct 72 ms 6436 KB Output is correct
19 Correct 72 ms 6436 KB Output is correct
20 Correct 36 ms 5776 KB Output is correct
21 Correct 20 ms 5512 KB Output is correct
22 Correct 24 ms 6436 KB Output is correct
23 Correct 36 ms 6964 KB Output is correct
24 Correct 32 ms 6964 KB Output is correct
25 Correct 28 ms 6568 KB Output is correct
26 Correct 80 ms 7624 KB Output is correct
27 Correct 48 ms 6568 KB Output is correct
28 Correct 28 ms 6040 KB Output is correct
29 Correct 40 ms 6436 KB Output is correct
30 Correct 44 ms 6304 KB Output is correct
31 Correct 40 ms 6304 KB Output is correct
32 Correct 16 ms 5512 KB Output is correct
33 Correct 20 ms 5504 KB Output is correct
34 Correct 20 ms 5428 KB Output is correct
35 Correct 4 ms 5116 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 5116 KB Output is correct
2 Correct 52 ms 5832 KB Output is correct
3 Correct 52 ms 5888 KB Output is correct
4 Correct 48 ms 6700 KB Output is correct
5 Correct 84 ms 8020 KB Output is correct
6 Correct 48 ms 6568 KB Output is correct
7 Correct 52 ms 8152 KB Output is correct
8 Correct 104 ms 6832 KB Output is correct
9 Correct 56 ms 5768 KB Output is correct
10 Correct 56 ms 5888 KB Output is correct
11 Correct 60 ms 6700 KB Output is correct
12 Correct 100 ms 8020 KB Output is correct
13 Correct 48 ms 6568 KB Output is correct
14 Correct 48 ms 8152 KB Output is correct
15 Correct 116 ms 6832 KB Output is correct
16 Correct 112 ms 6832 KB Output is correct
17 Correct 104 ms 6832 KB Output is correct
18 Correct 108 ms 6700 KB Output is correct
19 Correct 72 ms 6436 KB Output is correct
20 Correct 64 ms 6304 KB Output is correct
21 Correct 72 ms 6436 KB Output is correct
22 Correct 20 ms 5512 KB Output is correct
23 Correct 68 ms 6304 KB Output is correct
24 Correct 24 ms 5644 KB Output is correct
25 Correct 40 ms 5908 KB Output is correct
26 Correct 36 ms 5908 KB Output is correct
27 Correct 92 ms 6568 KB Output is correct
28 Correct 100 ms 6700 KB Output is correct
29 Correct 112 ms 6700 KB Output is correct
30 Correct 4 ms 5248 KB Output is correct
31 Correct 16 ms 5380 KB Output is correct
32 Correct 100 ms 6700 KB Output is correct
33 Correct 96 ms 6568 KB Output is correct
34 Correct 12 ms 5512 KB Output is correct
35 Correct 96 ms 6700 KB Output is correct
36 Correct 104 ms 6700 KB Output is correct
37 Correct 76 ms 6436 KB Output is correct
38 Correct 60 ms 6304 KB Output is correct
39 Correct 100 ms 6700 KB Output is correct
40 Correct 8 ms 5248 KB Output is correct
41 Correct 36 ms 5776 KB Output is correct
42 Correct 40 ms 7624 KB Output is correct
43 Correct 16 ms 6304 KB Output is correct
44 Correct 36 ms 6964 KB Output is correct
45 Correct 76 ms 7624 KB Output is correct
46 Correct 12 ms 5776 KB Output is correct
47 Correct 40 ms 7096 KB Output is correct
48 Correct 44 ms 7756 KB Output is correct
49 Correct 52 ms 8020 KB Output is correct
50 Correct 80 ms 7756 KB Output is correct
51 Correct 32 ms 6568 KB Output is correct
52 Correct 24 ms 6172 KB Output is correct
53 Correct 40 ms 6304 KB Output is correct
54 Correct 24 ms 5776 KB Output is correct
55 Correct 40 ms 6304 KB Output is correct
56 Correct 36 ms 5908 KB Output is correct
57 Correct 80 ms 6700 KB Output is correct
58 Correct 24 ms 5776 KB Output is correct
59 Correct 28 ms 5908 KB Output is correct
60 Correct 40 ms 6304 KB Output is correct
61 Correct 24 ms 5644 KB Output is correct
62 Correct 24 ms 6040 KB Output is correct
63 Correct 36 ms 6040 KB Output is correct
64 Correct 48 ms 5888 KB Output is correct
65 Correct 48 ms 5888 KB Output is correct
66 Correct 24 ms 5448 KB Output is correct
67 Correct 16 ms 5404 KB Output is correct
68 Correct 40 ms 5628 KB Output is correct
69 Correct 20 ms 5436 KB Output is correct
70 Correct 44 ms 5696 KB Output is correct
71 Correct 24 ms 5456 KB Output is correct
72 Correct 0 ms 5116 KB Output is correct