답안 #1057538

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1057538 2024-08-13T21:17:29 Z n1k 참나무 (IOI23_beechtree) C++17
80 / 100
2000 ms 255696 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] + c[u].size() < len[v] + c[v].size()){
                swap(c[u], c[v]);
                swap(len[u], len[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 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 0 ms 344 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 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 344 KB Output is correct
18 Correct 0 ms 344 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 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 436 KB Output is correct
31 Correct 0 ms 344 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 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 146 ms 116108 KB Output is correct
8 Correct 149 ms 116192 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 1 ms 348 KB Output is correct
13 Correct 1 ms 1372 KB Output is correct
14 Correct 2 ms 1368 KB Output is correct
15 Correct 1 ms 1372 KB Output is correct
16 Correct 1 ms 1496 KB Output is correct
17 Correct 147 ms 115880 KB Output is correct
18 Correct 150 ms 116052 KB Output is correct
19 Correct 151 ms 116180 KB Output is correct
20 Correct 168 ms 116264 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 604 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 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 952 KB Output is correct
12 Correct 1 ms 860 KB Output is correct
13 Correct 1 ms 908 KB Output is correct
14 Correct 2 ms 856 KB Output is correct
15 Correct 136 ms 51280 KB Output is correct
16 Correct 121 ms 47956 KB Output is correct
17 Correct 125 ms 48724 KB Output is correct
18 Correct 121 ms 50260 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 344 KB Output is correct
5 Correct 146 ms 116108 KB Output is correct
6 Correct 149 ms 116192 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 2 ms 1184 KB Output is correct
10 Correct 3 ms 1116 KB Output is correct
11 Correct 268 ms 97184 KB Output is correct
12 Execution timed out 2101 ms 25576 KB Time limit exceeded
13 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 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 344 KB Output is correct
12 Correct 1 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 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 344 KB Output is correct
21 Correct 0 ms 344 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 436 KB Output is correct
34 Correct 0 ms 344 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 0 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 1 ms 348 KB Output is correct
42 Correct 1 ms 348 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 0 ms 604 KB Output is correct
45 Correct 0 ms 348 KB Output is correct
46 Correct 0 ms 348 KB Output is correct
47 Correct 1 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 344 KB Output is correct
53 Correct 1 ms 348 KB Output is correct
54 Correct 1 ms 344 KB Output is correct
55 Correct 1 ms 348 KB Output is correct
56 Correct 0 ms 348 KB Output is correct
57 Correct 1 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 1 ms 344 KB Output is correct
62 Correct 1 ms 344 KB Output is correct
63 Correct 0 ms 344 KB Output is correct
64 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 344 KB Output is correct
5 Correct 1 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 344 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 344 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 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 2 ms 1372 KB Output is correct
26 Correct 1 ms 1372 KB Output is correct
27 Correct 1 ms 1372 KB Output is correct
28 Correct 1 ms 1372 KB Output is correct
29 Correct 1 ms 1372 KB Output is correct
30 Correct 2 ms 1372 KB Output is correct
31 Correct 3 ms 1740 KB Output is correct
32 Correct 3 ms 1628 KB Output is correct
33 Correct 3 ms 1372 KB Output is correct
34 Correct 3 ms 1884 KB Output is correct
35 Correct 3 ms 1884 KB Output is correct
36 Correct 3 ms 1372 KB Output is correct
37 Correct 1 ms 1116 KB Output is correct
38 Correct 2 ms 1372 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 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 344 KB Output is correct
12 Correct 1 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 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 344 KB Output is correct
21 Correct 0 ms 344 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 436 KB Output is correct
34 Correct 0 ms 344 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 0 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 1 ms 348 KB Output is correct
42 Correct 1 ms 1372 KB Output is correct
43 Correct 2 ms 1368 KB Output is correct
44 Correct 1 ms 1372 KB Output is correct
45 Correct 1 ms 1496 KB Output is correct
46 Correct 1 ms 348 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 0 ms 604 KB Output is correct
49 Correct 0 ms 348 KB Output is correct
50 Correct 0 ms 348 KB Output is correct
51 Correct 1 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 952 KB Output is correct
57 Correct 1 ms 860 KB Output is correct
58 Correct 1 ms 908 KB Output is correct
59 Correct 2 ms 856 KB Output is correct
60 Correct 1 ms 344 KB Output is correct
61 Correct 1 ms 348 KB Output is correct
62 Correct 2 ms 1184 KB Output is correct
63 Correct 3 ms 1116 KB Output is correct
64 Correct 1 ms 344 KB Output is correct
65 Correct 1 ms 348 KB Output is correct
66 Correct 0 ms 348 KB Output is correct
67 Correct 1 ms 348 KB Output is correct
68 Correct 0 ms 348 KB Output is correct
69 Correct 0 ms 348 KB Output is correct
70 Correct 0 ms 348 KB Output is correct
71 Correct 1 ms 344 KB Output is correct
72 Correct 1 ms 344 KB Output is correct
73 Correct 0 ms 344 KB Output is correct
74 Correct 0 ms 348 KB Output is correct
75 Correct 2 ms 1372 KB Output is correct
76 Correct 1 ms 1372 KB Output is correct
77 Correct 1 ms 1372 KB Output is correct
78 Correct 1 ms 1372 KB Output is correct
79 Correct 1 ms 1372 KB Output is correct
80 Correct 2 ms 1372 KB Output is correct
81 Correct 3 ms 1740 KB Output is correct
82 Correct 3 ms 1628 KB Output is correct
83 Correct 3 ms 1372 KB Output is correct
84 Correct 3 ms 1884 KB Output is correct
85 Correct 3 ms 1884 KB Output is correct
86 Correct 3 ms 1372 KB Output is correct
87 Correct 1 ms 1116 KB Output is correct
88 Correct 2 ms 1372 KB Output is correct
89 Correct 2 ms 1368 KB Output is correct
90 Correct 2 ms 1368 KB Output is correct
91 Correct 3 ms 1372 KB Output is correct
92 Correct 3 ms 1492 KB Output is correct
93 Correct 2 ms 1372 KB Output is correct
94 Correct 4 ms 1624 KB Output is correct
95 Correct 4 ms 1628 KB Output is correct
96 Correct 3 ms 1372 KB Output is correct
97 Correct 2 ms 1116 KB Output is correct
98 Correct 2 ms 1372 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 344 KB Output is correct
5 Correct 1 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 344 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 344 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 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 2 ms 1372 KB Output is correct
26 Correct 1 ms 1372 KB Output is correct
27 Correct 1 ms 1372 KB Output is correct
28 Correct 1 ms 1372 KB Output is correct
29 Correct 1 ms 1372 KB Output is correct
30 Correct 2 ms 1372 KB Output is correct
31 Correct 3 ms 1740 KB Output is correct
32 Correct 3 ms 1628 KB Output is correct
33 Correct 3 ms 1372 KB Output is correct
34 Correct 3 ms 1884 KB Output is correct
35 Correct 3 ms 1884 KB Output is correct
36 Correct 3 ms 1372 KB Output is correct
37 Correct 1 ms 1116 KB Output is correct
38 Correct 2 ms 1372 KB Output is correct
39 Correct 145 ms 115260 KB Output is correct
40 Correct 141 ms 115308 KB Output is correct
41 Correct 143 ms 115296 KB Output is correct
42 Correct 139 ms 115280 KB Output is correct
43 Correct 146 ms 103800 KB Output is correct
44 Correct 191 ms 99924 KB Output is correct
45 Correct 652 ms 217196 KB Output is correct
46 Correct 503 ms 193872 KB Output is correct
47 Correct 430 ms 167220 KB Output is correct
48 Correct 349 ms 132424 KB Output is correct
49 Correct 297 ms 102532 KB Output is correct
50 Correct 742 ms 255696 KB Output is correct
51 Correct 614 ms 231896 KB Output is correct
52 Correct 533 ms 187472 KB Output is correct
53 Correct 385 ms 141388 KB Output is correct
54 Correct 299 ms 102056 KB Output is correct
55 Correct 164 ms 91476 KB Output is correct
56 Correct 165 ms 91472 KB Output is correct
57 Correct 210 ms 97876 KB Output is correct
58 Correct 223 ms 98248 KB Output is correct
59 Correct 231 ms 98492 KB Output is correct
60 Correct 227 ms 98132 KB Output is correct
61 Correct 235 ms 97936 KB Output is correct
62 Correct 241 ms 97360 KB Output is correct
63 Correct 228 ms 91220 KB Output is correct
64 Correct 199 ms 100032 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 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 344 KB Output is correct
12 Correct 1 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 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 344 KB Output is correct
21 Correct 0 ms 344 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 436 KB Output is correct
34 Correct 0 ms 344 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 146 ms 116108 KB Output is correct
39 Correct 149 ms 116192 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 348 KB Output is correct
43 Correct 1 ms 348 KB Output is correct
44 Correct 1 ms 1372 KB Output is correct
45 Correct 2 ms 1368 KB Output is correct
46 Correct 1 ms 1372 KB Output is correct
47 Correct 1 ms 1496 KB Output is correct
48 Correct 147 ms 115880 KB Output is correct
49 Correct 150 ms 116052 KB Output is correct
50 Correct 151 ms 116180 KB Output is correct
51 Correct 168 ms 116264 KB Output is correct
52 Correct 1 ms 348 KB Output is correct
53 Correct 0 ms 348 KB Output is correct
54 Correct 0 ms 604 KB Output is correct
55 Correct 0 ms 348 KB Output is correct
56 Correct 0 ms 348 KB Output is correct
57 Correct 1 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 952 KB Output is correct
63 Correct 1 ms 860 KB Output is correct
64 Correct 1 ms 908 KB Output is correct
65 Correct 2 ms 856 KB Output is correct
66 Correct 136 ms 51280 KB Output is correct
67 Correct 121 ms 47956 KB Output is correct
68 Correct 125 ms 48724 KB Output is correct
69 Correct 121 ms 50260 KB Output is correct
70 Correct 1 ms 344 KB Output is correct
71 Correct 1 ms 348 KB Output is correct
72 Correct 2 ms 1184 KB Output is correct
73 Correct 3 ms 1116 KB Output is correct
74 Correct 268 ms 97184 KB Output is correct
75 Execution timed out 2101 ms 25576 KB Time limit exceeded
76 Halted 0 ms 0 KB -