답안 #1071204

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1071204 2024-08-23T05:51:56 Z Muhammad_Aneeq 참나무 (IOI23_beechtree) C++17
14 / 100
2000 ms 19932 KB
#include <vector>
#include <algorithm>
#include <set>
#include <iostream>
using namespace std;
int const MAXN=2e5+10;
vector<int>nei[MAXN]={};
int c[MAXN]={};
int h[MAXN]={};
int ans[MAXN]={};
int ind[MAXN]={};
int cnt[MAXN]={};
int p[MAXN]={};
bool check(vector<int>d,int u)
{
	for (auto i:d)
		ind[i]=-1,cnt[c[i]]=0;
	int z=1;
	for (auto i:d)
	{
		if (ind[p[i]]==-1)
			return 0;
		if (cnt[c[i]]!=ind[p[i]])
			return 0;
		ind[i]=z++;
		cnt[c[i]]++;
	}
	return 1;
}
vector<int> dfs(int u)
{
	vector<int>d;
	bool w=1;
	set<int>s;
	for (auto i:nei[u])
	{
		s.insert(c[i]);
		h[i]=h[u]+1;
		vector<int>f=dfs(i);
		for (auto i:f)
			d.push_back(i);
		w&=ans[i];
	}
	if (s.size()!=nei[u].size())
		w=0;
	if (w==0)
	{
		ans[u]=0;
		return {};
	}
	sort(begin(d),end(d));
	while (!check(d,u))
	{
		if (!next_permutation(begin(d),end(d)))
		{
			ans[u]=0;
			break;
		}
	}
	d.push_back(u);
	return d;
}
vector<int> beechtree(int N, int M, vector<int> P, vector<int> C)
{
	for (int i=0;i<N;i++)
		c[i]=C[i],p[i]=P[i],ans[i]=1;
	bool w=1;
	for (int i=1;i<N;i++)
	{
		nei[P[i]].push_back(i);
		if (P[i]!=i-1)
			w=0;
	}
	if (w)
	{
		vector<int>ans(N,0);
		ans[N-1]=1;
		for (int i=N-2;i>=0;i--)
		{
			if (c[i+1]==c[N-1])
				ans[i]=1;
			else
				break;
		}
		return ans;
	}
	dfs(0);
	vector<int>d;
	for (int i=0;i<N;i++)
		d.push_back(ans[i]);
	return d;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 7512 KB Output is correct
2 Correct 2 ms 9560 KB Output is correct
3 Correct 2 ms 9564 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 7516 KB Output is correct
2 Correct 1 ms 7516 KB Output is correct
3 Correct 1 ms 7516 KB Output is correct
4 Correct 2 ms 7516 KB Output is correct
5 Correct 1 ms 7612 KB Output is correct
6 Correct 1 ms 7516 KB Output is correct
7 Correct 1 ms 7516 KB Output is correct
8 Correct 2 ms 9564 KB Output is correct
9 Correct 2 ms 9564 KB Output is correct
10 Correct 1 ms 9564 KB Output is correct
11 Correct 2 ms 9564 KB Output is correct
12 Correct 1 ms 9564 KB Output is correct
13 Correct 2 ms 9564 KB Output is correct
14 Correct 2 ms 9564 KB Output is correct
15 Correct 2 ms 9560 KB Output is correct
16 Correct 2 ms 9816 KB Output is correct
17 Correct 2 ms 9564 KB Output is correct
18 Correct 1 ms 9564 KB Output is correct
19 Correct 1 ms 9564 KB Output is correct
20 Correct 1 ms 9564 KB Output is correct
21 Correct 1 ms 9564 KB Output is correct
22 Correct 1 ms 9564 KB Output is correct
23 Correct 1 ms 9564 KB Output is correct
24 Correct 1 ms 9564 KB Output is correct
25 Correct 1 ms 9564 KB Output is correct
26 Correct 1 ms 9564 KB Output is correct
27 Correct 1 ms 9560 KB Output is correct
28 Correct 1 ms 9564 KB Output is correct
29 Correct 1 ms 9564 KB Output is correct
30 Correct 1 ms 9564 KB Output is correct
31 Correct 1 ms 9564 KB Output is correct
32 Correct 2 ms 9564 KB Output is correct
33 Correct 1 ms 9564 KB Output is correct
34 Correct 1 ms 9564 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 7516 KB Output is correct
2 Correct 1 ms 7516 KB Output is correct
3 Correct 1 ms 7516 KB Output is correct
4 Correct 2 ms 7516 KB Output is correct
5 Correct 1 ms 7612 KB Output is correct
6 Correct 1 ms 7516 KB Output is correct
7 Correct 46 ms 19932 KB Output is correct
8 Correct 47 ms 19800 KB Output is correct
9 Correct 2 ms 7512 KB Output is correct
10 Correct 1 ms 7512 KB Output is correct
11 Correct 1 ms 7516 KB Output is correct
12 Correct 1 ms 7516 KB Output is correct
13 Correct 2 ms 7516 KB Output is correct
14 Correct 2 ms 7516 KB Output is correct
15 Correct 2 ms 7512 KB Output is correct
16 Correct 2 ms 7600 KB Output is correct
17 Correct 46 ms 19796 KB Output is correct
18 Correct 47 ms 19920 KB Output is correct
19 Correct 46 ms 19912 KB Output is correct
20 Correct 47 ms 19796 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 9560 KB Output is correct
2 Correct 2 ms 9564 KB Output is correct
3 Execution timed out 2098 ms 9660 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 7516 KB Output is correct
2 Correct 1 ms 7516 KB Output is correct
3 Correct 1 ms 7516 KB Output is correct
4 Correct 2 ms 9564 KB Output is correct
5 Correct 46 ms 19932 KB Output is correct
6 Correct 47 ms 19800 KB Output is correct
7 Execution timed out 2065 ms 9564 KB Time limit exceeded
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 7512 KB Output is correct
2 Correct 2 ms 9560 KB Output is correct
3 Correct 2 ms 9564 KB Output is correct
4 Correct 1 ms 7516 KB Output is correct
5 Correct 1 ms 7516 KB Output is correct
6 Correct 1 ms 7516 KB Output is correct
7 Correct 2 ms 7516 KB Output is correct
8 Correct 1 ms 7612 KB Output is correct
9 Correct 1 ms 7516 KB Output is correct
10 Correct 1 ms 7516 KB Output is correct
11 Correct 2 ms 9564 KB Output is correct
12 Correct 2 ms 9564 KB Output is correct
13 Correct 1 ms 9564 KB Output is correct
14 Correct 2 ms 9564 KB Output is correct
15 Correct 1 ms 9564 KB Output is correct
16 Correct 2 ms 9564 KB Output is correct
17 Correct 2 ms 9564 KB Output is correct
18 Correct 2 ms 9560 KB Output is correct
19 Correct 2 ms 9816 KB Output is correct
20 Correct 2 ms 9564 KB Output is correct
21 Correct 1 ms 9564 KB Output is correct
22 Correct 1 ms 9564 KB Output is correct
23 Correct 1 ms 9564 KB Output is correct
24 Correct 1 ms 9564 KB Output is correct
25 Correct 1 ms 9564 KB Output is correct
26 Correct 1 ms 9564 KB Output is correct
27 Correct 1 ms 9564 KB Output is correct
28 Correct 1 ms 9564 KB Output is correct
29 Correct 1 ms 9564 KB Output is correct
30 Correct 1 ms 9560 KB Output is correct
31 Correct 1 ms 9564 KB Output is correct
32 Correct 1 ms 9564 KB Output is correct
33 Correct 1 ms 9564 KB Output is correct
34 Correct 1 ms 9564 KB Output is correct
35 Correct 2 ms 9564 KB Output is correct
36 Correct 1 ms 9564 KB Output is correct
37 Correct 1 ms 9564 KB Output is correct
38 Correct 2 ms 7512 KB Output is correct
39 Correct 1 ms 7512 KB Output is correct
40 Correct 1 ms 7516 KB Output is correct
41 Correct 1 ms 7516 KB Output is correct
42 Correct 2 ms 9560 KB Output is correct
43 Correct 2 ms 9564 KB Output is correct
44 Execution timed out 2098 ms 9660 KB Time limit exceeded
45 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 7516 KB Output is correct
2 Correct 1 ms 7516 KB Output is correct
3 Correct 1 ms 7516 KB Output is correct
4 Correct 2 ms 9564 KB Output is correct
5 Correct 2 ms 9564 KB Output is correct
6 Correct 1 ms 9564 KB Output is correct
7 Correct 2 ms 9564 KB Output is correct
8 Correct 1 ms 9564 KB Output is correct
9 Correct 2 ms 9564 KB Output is correct
10 Correct 2 ms 9564 KB Output is correct
11 Correct 2 ms 9560 KB Output is correct
12 Correct 2 ms 9816 KB Output is correct
13 Correct 2 ms 9564 KB Output is correct
14 Correct 1 ms 9564 KB Output is correct
15 Correct 1 ms 9564 KB Output is correct
16 Correct 1 ms 9564 KB Output is correct
17 Correct 1 ms 9564 KB Output is correct
18 Correct 1 ms 9564 KB Output is correct
19 Correct 1 ms 9564 KB Output is correct
20 Correct 1 ms 9564 KB Output is correct
21 Correct 1 ms 9564 KB Output is correct
22 Correct 1 ms 9564 KB Output is correct
23 Correct 1 ms 9560 KB Output is correct
24 Correct 1 ms 9564 KB Output is correct
25 Correct 2 ms 7512 KB Output is correct
26 Correct 2 ms 7516 KB Output is correct
27 Correct 2 ms 7516 KB Output is correct
28 Correct 2 ms 7516 KB Output is correct
29 Correct 2 ms 7516 KB Output is correct
30 Execution timed out 2099 ms 9652 KB Time limit exceeded
31 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 7512 KB Output is correct
2 Correct 2 ms 9560 KB Output is correct
3 Correct 2 ms 9564 KB Output is correct
4 Correct 1 ms 7516 KB Output is correct
5 Correct 1 ms 7516 KB Output is correct
6 Correct 1 ms 7516 KB Output is correct
7 Correct 2 ms 7516 KB Output is correct
8 Correct 1 ms 7612 KB Output is correct
9 Correct 1 ms 7516 KB Output is correct
10 Correct 1 ms 7516 KB Output is correct
11 Correct 2 ms 9564 KB Output is correct
12 Correct 2 ms 9564 KB Output is correct
13 Correct 1 ms 9564 KB Output is correct
14 Correct 2 ms 9564 KB Output is correct
15 Correct 1 ms 9564 KB Output is correct
16 Correct 2 ms 9564 KB Output is correct
17 Correct 2 ms 9564 KB Output is correct
18 Correct 2 ms 9560 KB Output is correct
19 Correct 2 ms 9816 KB Output is correct
20 Correct 2 ms 9564 KB Output is correct
21 Correct 1 ms 9564 KB Output is correct
22 Correct 1 ms 9564 KB Output is correct
23 Correct 1 ms 9564 KB Output is correct
24 Correct 1 ms 9564 KB Output is correct
25 Correct 1 ms 9564 KB Output is correct
26 Correct 1 ms 9564 KB Output is correct
27 Correct 1 ms 9564 KB Output is correct
28 Correct 1 ms 9564 KB Output is correct
29 Correct 1 ms 9564 KB Output is correct
30 Correct 1 ms 9560 KB Output is correct
31 Correct 1 ms 9564 KB Output is correct
32 Correct 1 ms 9564 KB Output is correct
33 Correct 1 ms 9564 KB Output is correct
34 Correct 1 ms 9564 KB Output is correct
35 Correct 2 ms 9564 KB Output is correct
36 Correct 1 ms 9564 KB Output is correct
37 Correct 1 ms 9564 KB Output is correct
38 Correct 2 ms 7512 KB Output is correct
39 Correct 1 ms 7512 KB Output is correct
40 Correct 1 ms 7516 KB Output is correct
41 Correct 1 ms 7516 KB Output is correct
42 Correct 2 ms 7516 KB Output is correct
43 Correct 2 ms 7516 KB Output is correct
44 Correct 2 ms 7512 KB Output is correct
45 Correct 2 ms 7600 KB Output is correct
46 Correct 2 ms 9560 KB Output is correct
47 Correct 2 ms 9564 KB Output is correct
48 Execution timed out 2098 ms 9660 KB Time limit exceeded
49 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 7516 KB Output is correct
2 Correct 1 ms 7516 KB Output is correct
3 Correct 1 ms 7516 KB Output is correct
4 Correct 2 ms 9564 KB Output is correct
5 Correct 2 ms 9564 KB Output is correct
6 Correct 1 ms 9564 KB Output is correct
7 Correct 2 ms 9564 KB Output is correct
8 Correct 1 ms 9564 KB Output is correct
9 Correct 2 ms 9564 KB Output is correct
10 Correct 2 ms 9564 KB Output is correct
11 Correct 2 ms 9560 KB Output is correct
12 Correct 2 ms 9816 KB Output is correct
13 Correct 2 ms 9564 KB Output is correct
14 Correct 1 ms 9564 KB Output is correct
15 Correct 1 ms 9564 KB Output is correct
16 Correct 1 ms 9564 KB Output is correct
17 Correct 1 ms 9564 KB Output is correct
18 Correct 1 ms 9564 KB Output is correct
19 Correct 1 ms 9564 KB Output is correct
20 Correct 1 ms 9564 KB Output is correct
21 Correct 1 ms 9564 KB Output is correct
22 Correct 1 ms 9564 KB Output is correct
23 Correct 1 ms 9560 KB Output is correct
24 Correct 1 ms 9564 KB Output is correct
25 Correct 2 ms 7512 KB Output is correct
26 Correct 2 ms 7516 KB Output is correct
27 Correct 2 ms 7516 KB Output is correct
28 Correct 2 ms 7516 KB Output is correct
29 Correct 2 ms 7516 KB Output is correct
30 Execution timed out 2099 ms 9652 KB Time limit exceeded
31 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 7512 KB Output is correct
2 Correct 2 ms 9560 KB Output is correct
3 Correct 2 ms 9564 KB Output is correct
4 Correct 1 ms 7516 KB Output is correct
5 Correct 1 ms 7516 KB Output is correct
6 Correct 1 ms 7516 KB Output is correct
7 Correct 2 ms 7516 KB Output is correct
8 Correct 1 ms 7612 KB Output is correct
9 Correct 1 ms 7516 KB Output is correct
10 Correct 1 ms 7516 KB Output is correct
11 Correct 2 ms 9564 KB Output is correct
12 Correct 2 ms 9564 KB Output is correct
13 Correct 1 ms 9564 KB Output is correct
14 Correct 2 ms 9564 KB Output is correct
15 Correct 1 ms 9564 KB Output is correct
16 Correct 2 ms 9564 KB Output is correct
17 Correct 2 ms 9564 KB Output is correct
18 Correct 2 ms 9560 KB Output is correct
19 Correct 2 ms 9816 KB Output is correct
20 Correct 2 ms 9564 KB Output is correct
21 Correct 1 ms 9564 KB Output is correct
22 Correct 1 ms 9564 KB Output is correct
23 Correct 1 ms 9564 KB Output is correct
24 Correct 1 ms 9564 KB Output is correct
25 Correct 1 ms 9564 KB Output is correct
26 Correct 1 ms 9564 KB Output is correct
27 Correct 1 ms 9564 KB Output is correct
28 Correct 1 ms 9564 KB Output is correct
29 Correct 1 ms 9564 KB Output is correct
30 Correct 1 ms 9560 KB Output is correct
31 Correct 1 ms 9564 KB Output is correct
32 Correct 1 ms 9564 KB Output is correct
33 Correct 1 ms 9564 KB Output is correct
34 Correct 1 ms 9564 KB Output is correct
35 Correct 2 ms 9564 KB Output is correct
36 Correct 1 ms 9564 KB Output is correct
37 Correct 1 ms 9564 KB Output is correct
38 Correct 46 ms 19932 KB Output is correct
39 Correct 47 ms 19800 KB Output is correct
40 Correct 2 ms 7512 KB Output is correct
41 Correct 1 ms 7512 KB Output is correct
42 Correct 1 ms 7516 KB Output is correct
43 Correct 1 ms 7516 KB Output is correct
44 Correct 2 ms 7516 KB Output is correct
45 Correct 2 ms 7516 KB Output is correct
46 Correct 2 ms 7512 KB Output is correct
47 Correct 2 ms 7600 KB Output is correct
48 Correct 46 ms 19796 KB Output is correct
49 Correct 47 ms 19920 KB Output is correct
50 Correct 46 ms 19912 KB Output is correct
51 Correct 47 ms 19796 KB Output is correct
52 Correct 2 ms 9560 KB Output is correct
53 Correct 2 ms 9564 KB Output is correct
54 Execution timed out 2098 ms 9660 KB Time limit exceeded
55 Halted 0 ms 0 KB -