답안 #1057525

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1057525 2024-08-13T20:59:49 Z n1k 참나무 (IOI23_beechtree) C++17
63 / 100
2000 ms 927664 KB
#include "beechtree.h"
#include <bits/stdc++.h>

using namespace std;

std::vector<int> beechtree(int N, int M, std::vector<int> P, std::vector<int> C){
    vector<multiset<pair<int, map<int, int>>>> c(N);
    vector<vector<int>> g(N);
    vector<int> ans(N, 1), sz(N, 1), len(N);
    for(int i=1; i<N; i++){
        g[P[i]].push_back(i);
    }
    auto check = [&](auto a, auto b){
        bool ok = a.size() >= b.size();
        for(auto [k, v]:b){
            ok &= a[k]>=v;
        }
        return ok;
    };
    auto add = [&](auto p, auto u){
        len[u]+=p.second.size();
        bool ok = 1;
        auto it = c[u].insert(p);
        if(next(it)!=c[u].end()){
            ok&=check(next(it)->second, it->second);
        }
        if(it!=c[u].begin()){
            ok&=check(it->second, prev(it)->second);
        } 
        return ok;
    };
    function<void(int)> dfs = [&](int u){
        map<int, int> cur;
        for(auto v:g[u]){
            dfs(v);
            sz[u]+=sz[v];
            ans[u]&=ans[v];
            ans[u]&= !cur.count(C[v]);
            cur[C[v]] = sz[v];

            if(len[u] < len[v]){
                swap(c[u], c[v]);
            }
            // insert
            for(auto p:c[v]){
                ans[u]&=add(p, u);
            }
        }
        ans[u]&=add(make_pair(sz[u], cur), u);
    };

    dfs(0);

    return ans;
}
# 결과 실행 시간 메모리 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
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 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 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 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 0 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 344 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 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
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 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 149 ms 113796 KB Output is correct
8 Correct 147 ms 113748 KB Output is correct
9 Correct 1 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 348 KB Output is correct
13 Correct 1 ms 1372 KB Output is correct
14 Correct 1 ms 1372 KB Output is correct
15 Correct 2 ms 1372 KB Output is correct
16 Correct 3 ms 1372 KB Output is correct
17 Correct 137 ms 113740 KB Output is correct
18 Correct 142 ms 113748 KB Output is correct
19 Correct 171 ms 113748 KB Output is correct
20 Correct 150 ms 113760 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 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 344 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 348 KB Output is correct
11 Correct 1 ms 860 KB Output is correct
12 Correct 1 ms 860 KB Output is correct
13 Correct 1 ms 860 KB Output is correct
14 Correct 2 ms 856 KB Output is correct
15 Correct 131 ms 50128 KB Output is correct
16 Correct 125 ms 47184 KB Output is correct
17 Correct 128 ms 47952 KB Output is correct
18 Correct 129 ms 49236 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 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 149 ms 113796 KB Output is correct
6 Correct 147 ms 113748 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 2 ms 1372 KB Output is correct
10 Correct 3 ms 1116 KB Output is correct
11 Correct 285 ms 98996 KB Output is correct
12 Execution timed out 2025 ms 23632 KB Time limit exceeded
13 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 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 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 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 0 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 344 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
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 1 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 0 ms 348 KB Output is correct
41 Correct 0 ms 348 KB Output is correct
42 Correct 0 ms 344 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 0 ms 348 KB Output is correct
45 Correct 0 ms 344 KB Output is correct
46 Correct 0 ms 348 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 0 ms 348 KB Output is correct
50 Correct 0 ms 348 KB Output is correct
51 Correct 0 ms 348 KB Output is correct
52 Correct 1 ms 348 KB Output is correct
53 Correct 0 ms 348 KB Output is correct
54 Correct 1 ms 348 KB Output is correct
55 Correct 1 ms 348 KB Output is correct
56 Correct 1 ms 604 KB Output is correct
57 Correct 1 ms 344 KB Output is correct
58 Correct 0 ms 348 KB Output is correct
59 Correct 1 ms 348 KB Output is correct
60 Correct 1 ms 348 KB Output is correct
61 Correct 1 ms 348 KB Output is correct
62 Correct 1 ms 600 KB Output is correct
63 Correct 0 ms 344 KB Output is correct
64 Correct 0 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 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 0 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 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 344 KB Output is correct
16 Correct 0 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 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 1368 KB Output is correct
26 Correct 2 ms 1372 KB Output is correct
27 Correct 2 ms 1372 KB Output is correct
28 Correct 2 ms 1368 KB Output is correct
29 Correct 1 ms 1624 KB Output is correct
30 Correct 3 ms 1884 KB Output is correct
31 Correct 4 ms 2608 KB Output is correct
32 Correct 6 ms 2908 KB Output is correct
33 Correct 18 ms 6952 KB Output is correct
34 Correct 4 ms 2136 KB Output is correct
35 Correct 7 ms 2136 KB Output is correct
36 Correct 4 ms 1628 KB Output is correct
37 Correct 2 ms 1112 KB Output is correct
38 Correct 3 ms 1372 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 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 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 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 0 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 344 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
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 1 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 0 ms 348 KB Output is correct
41 Correct 0 ms 348 KB Output is correct
42 Correct 1 ms 1372 KB Output is correct
43 Correct 1 ms 1372 KB Output is correct
44 Correct 2 ms 1372 KB Output is correct
45 Correct 3 ms 1372 KB Output is correct
46 Correct 0 ms 344 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 0 ms 344 KB Output is correct
50 Correct 0 ms 348 KB Output is correct
51 Correct 0 ms 348 KB Output is correct
52 Correct 0 ms 348 KB Output is correct
53 Correct 0 ms 348 KB Output is correct
54 Correct 0 ms 348 KB Output is correct
55 Correct 0 ms 348 KB Output is correct
56 Correct 1 ms 860 KB Output is correct
57 Correct 1 ms 860 KB Output is correct
58 Correct 1 ms 860 KB Output is correct
59 Correct 2 ms 856 KB Output is correct
60 Correct 1 ms 348 KB Output is correct
61 Correct 0 ms 348 KB Output is correct
62 Correct 2 ms 1372 KB Output is correct
63 Correct 3 ms 1116 KB Output is correct
64 Correct 1 ms 348 KB Output is correct
65 Correct 1 ms 348 KB Output is correct
66 Correct 1 ms 604 KB Output is correct
67 Correct 1 ms 344 KB Output is correct
68 Correct 0 ms 348 KB Output is correct
69 Correct 1 ms 348 KB Output is correct
70 Correct 1 ms 348 KB Output is correct
71 Correct 1 ms 348 KB Output is correct
72 Correct 1 ms 600 KB Output is correct
73 Correct 0 ms 344 KB Output is correct
74 Correct 0 ms 344 KB Output is correct
75 Correct 1 ms 1368 KB Output is correct
76 Correct 2 ms 1372 KB Output is correct
77 Correct 2 ms 1372 KB Output is correct
78 Correct 2 ms 1368 KB Output is correct
79 Correct 1 ms 1624 KB Output is correct
80 Correct 3 ms 1884 KB Output is correct
81 Correct 4 ms 2608 KB Output is correct
82 Correct 6 ms 2908 KB Output is correct
83 Correct 18 ms 6952 KB Output is correct
84 Correct 4 ms 2136 KB Output is correct
85 Correct 7 ms 2136 KB Output is correct
86 Correct 4 ms 1628 KB Output is correct
87 Correct 2 ms 1112 KB Output is correct
88 Correct 3 ms 1372 KB Output is correct
89 Correct 2 ms 1372 KB Output is correct
90 Correct 3 ms 1624 KB Output is correct
91 Correct 5 ms 2140 KB Output is correct
92 Correct 5 ms 2392 KB Output is correct
93 Correct 18 ms 6748 KB Output is correct
94 Correct 4 ms 1628 KB Output is correct
95 Correct 4 ms 1884 KB Output is correct
96 Correct 3 ms 1628 KB Output is correct
97 Correct 2 ms 1112 KB Output is correct
98 Correct 3 ms 1372 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 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 0 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 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 344 KB Output is correct
16 Correct 0 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 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 1368 KB Output is correct
26 Correct 2 ms 1372 KB Output is correct
27 Correct 2 ms 1372 KB Output is correct
28 Correct 2 ms 1368 KB Output is correct
29 Correct 1 ms 1624 KB Output is correct
30 Correct 3 ms 1884 KB Output is correct
31 Correct 4 ms 2608 KB Output is correct
32 Correct 6 ms 2908 KB Output is correct
33 Correct 18 ms 6952 KB Output is correct
34 Correct 4 ms 2136 KB Output is correct
35 Correct 7 ms 2136 KB Output is correct
36 Correct 4 ms 1628 KB Output is correct
37 Correct 2 ms 1112 KB Output is correct
38 Correct 3 ms 1372 KB Output is correct
39 Correct 137 ms 113880 KB Output is correct
40 Correct 142 ms 113748 KB Output is correct
41 Correct 153 ms 113844 KB Output is correct
42 Correct 146 ms 113736 KB Output is correct
43 Correct 410 ms 188880 KB Output is correct
44 Correct 439 ms 191824 KB Output is correct
45 Correct 974 ms 342256 KB Output is correct
46 Correct 1154 ms 438608 KB Output is correct
47 Correct 652 ms 257888 KB Output is correct
48 Execution timed out 2101 ms 927664 KB Time limit exceeded
49 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 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 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 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 0 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 344 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
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 149 ms 113796 KB Output is correct
39 Correct 147 ms 113748 KB Output is correct
40 Correct 1 ms 348 KB Output is correct
41 Correct 0 ms 348 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 1 ms 1372 KB Output is correct
45 Correct 1 ms 1372 KB Output is correct
46 Correct 2 ms 1372 KB Output is correct
47 Correct 3 ms 1372 KB Output is correct
48 Correct 137 ms 113740 KB Output is correct
49 Correct 142 ms 113748 KB Output is correct
50 Correct 171 ms 113748 KB Output is correct
51 Correct 150 ms 113760 KB Output is correct
52 Correct 0 ms 344 KB Output is correct
53 Correct 0 ms 348 KB Output is correct
54 Correct 0 ms 348 KB Output is correct
55 Correct 0 ms 344 KB Output is correct
56 Correct 0 ms 348 KB Output is correct
57 Correct 0 ms 348 KB Output is correct
58 Correct 0 ms 348 KB Output is correct
59 Correct 0 ms 348 KB Output is correct
60 Correct 0 ms 348 KB Output is correct
61 Correct 0 ms 348 KB Output is correct
62 Correct 1 ms 860 KB Output is correct
63 Correct 1 ms 860 KB Output is correct
64 Correct 1 ms 860 KB Output is correct
65 Correct 2 ms 856 KB Output is correct
66 Correct 131 ms 50128 KB Output is correct
67 Correct 125 ms 47184 KB Output is correct
68 Correct 128 ms 47952 KB Output is correct
69 Correct 129 ms 49236 KB Output is correct
70 Correct 1 ms 348 KB Output is correct
71 Correct 0 ms 348 KB Output is correct
72 Correct 2 ms 1372 KB Output is correct
73 Correct 3 ms 1116 KB Output is correct
74 Correct 285 ms 98996 KB Output is correct
75 Execution timed out 2025 ms 23632 KB Time limit exceeded
76 Halted 0 ms 0 KB -