Submission #1105989

# Submission time Handle Problem Language Result Execution time Memory
1105989 2024-10-28T16:10:31 Z underwaterkillerwhale Team Coding (EGOI24_teamcoding) C++17
100 / 100
979 ms 28752 KB
#include <bits/stdc++.h>
#define ll long long
#define rep(i,m,n) for(int i=(m); i<=(n); i++)
#define reb(i,m,n) for(int i=(m); i>=(n); i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define MP make_pair
#define fs first
#define se second
#define bit(msk, i) ((msk >> i) & 1)
#define iter(id, v) for(auto id : v)
#define pb push_back
#define SZ(v) (ll)v.size()
#define ALL(v) v.begin(),v.end()

using namespace std;

mt19937_64 rd(chrono :: steady_clock :: now ().time_since_epoch().count());
ll Rand (ll l, ll r) { return uniform_int_distribution<ll> (l, r) (rd); }

const int N = 1e5 + 7;
const int Mod = 1e6 + 3;///lon
const ll INF = 1e18 + 7;
const ll BASE = 137;
const int szBL = 350;

int n, K;
int a[N];
vector<int> ke[N];
vector<int> setC[N], setH[N];///setC node màu C, setHi các node tại high i (lưu cái ein);
int ein[N], eout[N], high[N], numC[N], iniC[N], par[N], curR[N], maxH[N];///số C đã có sẵn trong root
bool covered[N];

void solution () {
    cin >> n >> K;
    rep (i, 1, n) {
        cin >> a[i];
        ++a[i];
        setC[a[i]].pb(i);
    }
    rep (i, 2, n) {
        cin >> par[i];
        ++par[i];
        ke[par[i]].pb(i);
    }
    function<void(int)> pdfs = [&] (int u) {
        static int time_dfs = 0;
        ein[u] = ++time_dfs;

        if (numC[a[u]]) covered[u] = 1;
        else curR[a[u]] = u;

        numC[a[u]]++;
        setH[high[u]].pb(ein[u]);
        iniC[curR[a[u]]]++;
        maxH[u] = high[u];
        iter (&v, ke[u]) {
            high[v] = high[u] + 1;
            pdfs (v);
            maxH[u] = max(maxH[u], maxH[v]);
        }
        eout[u] = time_dfs;
        --numC[a[u]];
    };
    pdfs(1);
    pii res = {-1, 0};
    auto get = [&] (int L, int R, int H) -> int {
        return (upper_bound(ALL(setH[H]), R) - setH[H].begin() - 1) - (lower_bound(ALL(setH[H]), L) - setH[H].begin() - 1);
    };
    auto process = [&] (int col) {
        vector<int> root, vecH;
        iter (&id, setC[col]) {
            if (!covered[id]) root.pb(id);
            numC[high[id]]++;
            vecH.pb(high[id]);
        }
        sort (ALL(vecH));
        vecH.resize(unique(ALL(vecH)) - vecH.begin());
        iter (&u, root) {
            int ansu = 0;
            iter (&H, vecH) {
                if (H > maxH[u]) break;
                if (H < high[u]) continue;
                ansu += min(numC[H], get(ein[u], eout[u], H));
            }
            res = max(res, {ansu, iniC[u]});
        }
        iter (&id, vecH) numC[id] = 0;
    };
    rep (i, 1, K) process(i);
    cout << res.fs <<" "<<res.fs - res.se <<"\n";
}

#define file(name) freopen(name".inp","r",stdin); \
freopen(name".out","w",stdout);
main () {
//    file("c");
    ios_base :: sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int num_Test = 1;
//    cin >> num_Test;
    while (num_Test--)
        solution();
}
/*
no bug challenge +12
*/

Compilation message

Main.cpp:96:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   96 | main () {
      | ^~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8528 KB Output is correct
2 Correct 2 ms 10576 KB Output is correct
3 Correct 2 ms 10576 KB Output is correct
4 Correct 2 ms 10576 KB Output is correct
5 Correct 2 ms 10576 KB Output is correct
6 Correct 2 ms 10688 KB Output is correct
7 Correct 3 ms 10576 KB Output is correct
8 Correct 2 ms 10832 KB Output is correct
9 Correct 45 ms 28232 KB Output is correct
10 Correct 2 ms 10576 KB Output is correct
11 Correct 2 ms 10832 KB Output is correct
12 Correct 31 ms 27596 KB Output is correct
13 Correct 2 ms 10744 KB Output is correct
14 Correct 2 ms 11028 KB Output is correct
15 Correct 48 ms 28752 KB Output is correct
16 Correct 2 ms 10576 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8528 KB Output is correct
2 Correct 2 ms 10576 KB Output is correct
3 Correct 2 ms 10576 KB Output is correct
4 Correct 4 ms 10832 KB Output is correct
5 Correct 32 ms 27500 KB Output is correct
6 Correct 2 ms 10576 KB Output is correct
7 Correct 2 ms 10744 KB Output is correct
8 Correct 28 ms 14800 KB Output is correct
9 Correct 2 ms 10576 KB Output is correct
10 Correct 3 ms 10832 KB Output is correct
11 Correct 902 ms 20088 KB Output is correct
12 Correct 21 ms 13528 KB Output is correct
13 Correct 3 ms 10744 KB Output is correct
14 Correct 2 ms 10576 KB Output is correct
15 Correct 27 ms 13984 KB Output is correct
16 Correct 24 ms 14056 KB Output is correct
17 Correct 2 ms 10828 KB Output is correct
18 Correct 2 ms 10576 KB Output is correct
19 Correct 27 ms 14348 KB Output is correct
20 Correct 26 ms 14244 KB Output is correct
21 Correct 25 ms 14220 KB Output is correct
22 Correct 3 ms 10576 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8528 KB Output is correct
2 Correct 2 ms 10576 KB Output is correct
3 Correct 2 ms 10576 KB Output is correct
4 Correct 2 ms 10576 KB Output is correct
5 Correct 2 ms 10576 KB Output is correct
6 Correct 2 ms 10576 KB Output is correct
7 Correct 2 ms 10576 KB Output is correct
8 Correct 61 ms 28264 KB Output is correct
9 Correct 3 ms 10576 KB Output is correct
10 Correct 3 ms 11088 KB Output is correct
11 Correct 57 ms 28700 KB Output is correct
12 Correct 2 ms 10576 KB Output is correct
13 Correct 2 ms 10576 KB Output is correct
14 Correct 2 ms 10576 KB Output is correct
15 Correct 4 ms 10576 KB Output is correct
16 Correct 3 ms 10576 KB Output is correct
17 Correct 3 ms 10576 KB Output is correct
18 Correct 60 ms 15016 KB Output is correct
19 Correct 56 ms 15184 KB Output is correct
20 Correct 44 ms 17308 KB Output is correct
21 Correct 51 ms 13648 KB Output is correct
22 Correct 58 ms 14416 KB Output is correct
23 Correct 58 ms 21840 KB Output is correct
24 Correct 51 ms 19360 KB Output is correct
25 Correct 3 ms 10832 KB Output is correct
26 Correct 3 ms 10832 KB Output is correct
27 Correct 3 ms 10576 KB Output is correct
28 Correct 4 ms 10832 KB Output is correct
29 Correct 6 ms 11088 KB Output is correct
30 Correct 55 ms 14672 KB Output is correct
31 Correct 53 ms 15444 KB Output is correct
32 Correct 49 ms 18268 KB Output is correct
33 Correct 60 ms 14416 KB Output is correct
34 Correct 3 ms 10576 KB Output is correct
35 Correct 2 ms 10576 KB Output is correct
36 Correct 2 ms 10576 KB Output is correct
37 Correct 3 ms 10576 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8528 KB Output is correct
2 Correct 2 ms 10576 KB Output is correct
3 Correct 2 ms 10576 KB Output is correct
4 Correct 2 ms 10576 KB Output is correct
5 Correct 2 ms 10576 KB Output is correct
6 Correct 2 ms 10576 KB Output is correct
7 Correct 2 ms 10576 KB Output is correct
8 Correct 3 ms 10832 KB Output is correct
9 Correct 2 ms 10576 KB Output is correct
10 Correct 2 ms 10832 KB Output is correct
11 Correct 2 ms 10576 KB Output is correct
12 Correct 3 ms 11088 KB Output is correct
13 Correct 2 ms 10576 KB Output is correct
14 Correct 2 ms 10576 KB Output is correct
15 Correct 2 ms 10576 KB Output is correct
16 Correct 3 ms 10832 KB Output is correct
17 Correct 3 ms 10588 KB Output is correct
18 Correct 3 ms 10692 KB Output is correct
19 Correct 2 ms 10588 KB Output is correct
20 Correct 3 ms 10576 KB Output is correct
21 Correct 2 ms 10576 KB Output is correct
22 Correct 2 ms 10576 KB Output is correct
23 Correct 3 ms 10576 KB Output is correct
24 Correct 3 ms 10744 KB Output is correct
25 Correct 3 ms 10576 KB Output is correct
26 Correct 3 ms 10832 KB Output is correct
27 Correct 3 ms 10832 KB Output is correct
28 Correct 3 ms 10688 KB Output is correct
29 Correct 3 ms 10832 KB Output is correct
30 Correct 3 ms 10832 KB Output is correct
31 Correct 3 ms 10832 KB Output is correct
32 Correct 3 ms 10576 KB Output is correct
33 Correct 2 ms 10848 KB Output is correct
34 Correct 3 ms 10576 KB Output is correct
35 Correct 3 ms 10576 KB Output is correct
36 Correct 2 ms 10576 KB Output is correct
37 Correct 2 ms 10576 KB Output is correct
38 Correct 2 ms 10576 KB Output is correct
39 Correct 2 ms 10576 KB Output is correct
40 Correct 2 ms 10576 KB Output is correct
41 Correct 2 ms 10576 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8528 KB Output is correct
2 Correct 2 ms 10576 KB Output is correct
3 Correct 2 ms 10576 KB Output is correct
4 Correct 2 ms 10576 KB Output is correct
5 Correct 2 ms 10576 KB Output is correct
6 Correct 2 ms 10688 KB Output is correct
7 Correct 3 ms 10576 KB Output is correct
8 Correct 2 ms 10832 KB Output is correct
9 Correct 45 ms 28232 KB Output is correct
10 Correct 2 ms 10576 KB Output is correct
11 Correct 2 ms 10832 KB Output is correct
12 Correct 31 ms 27596 KB Output is correct
13 Correct 2 ms 10744 KB Output is correct
14 Correct 2 ms 11028 KB Output is correct
15 Correct 48 ms 28752 KB Output is correct
16 Correct 2 ms 10576 KB Output is correct
17 Correct 2 ms 8528 KB Output is correct
18 Correct 2 ms 10576 KB Output is correct
19 Correct 2 ms 10576 KB Output is correct
20 Correct 4 ms 10832 KB Output is correct
21 Correct 32 ms 27500 KB Output is correct
22 Correct 2 ms 10576 KB Output is correct
23 Correct 2 ms 10744 KB Output is correct
24 Correct 28 ms 14800 KB Output is correct
25 Correct 2 ms 10576 KB Output is correct
26 Correct 3 ms 10832 KB Output is correct
27 Correct 902 ms 20088 KB Output is correct
28 Correct 21 ms 13528 KB Output is correct
29 Correct 3 ms 10744 KB Output is correct
30 Correct 2 ms 10576 KB Output is correct
31 Correct 27 ms 13984 KB Output is correct
32 Correct 24 ms 14056 KB Output is correct
33 Correct 2 ms 10828 KB Output is correct
34 Correct 2 ms 10576 KB Output is correct
35 Correct 27 ms 14348 KB Output is correct
36 Correct 26 ms 14244 KB Output is correct
37 Correct 25 ms 14220 KB Output is correct
38 Correct 3 ms 10576 KB Output is correct
39 Correct 2 ms 8528 KB Output is correct
40 Correct 2 ms 10576 KB Output is correct
41 Correct 2 ms 10576 KB Output is correct
42 Correct 2 ms 10576 KB Output is correct
43 Correct 2 ms 10576 KB Output is correct
44 Correct 2 ms 10576 KB Output is correct
45 Correct 2 ms 10576 KB Output is correct
46 Correct 61 ms 28264 KB Output is correct
47 Correct 3 ms 10576 KB Output is correct
48 Correct 3 ms 11088 KB Output is correct
49 Correct 57 ms 28700 KB Output is correct
50 Correct 2 ms 10576 KB Output is correct
51 Correct 2 ms 10576 KB Output is correct
52 Correct 2 ms 10576 KB Output is correct
53 Correct 4 ms 10576 KB Output is correct
54 Correct 3 ms 10576 KB Output is correct
55 Correct 3 ms 10576 KB Output is correct
56 Correct 60 ms 15016 KB Output is correct
57 Correct 56 ms 15184 KB Output is correct
58 Correct 44 ms 17308 KB Output is correct
59 Correct 51 ms 13648 KB Output is correct
60 Correct 58 ms 14416 KB Output is correct
61 Correct 58 ms 21840 KB Output is correct
62 Correct 51 ms 19360 KB Output is correct
63 Correct 3 ms 10832 KB Output is correct
64 Correct 3 ms 10832 KB Output is correct
65 Correct 3 ms 10576 KB Output is correct
66 Correct 4 ms 10832 KB Output is correct
67 Correct 6 ms 11088 KB Output is correct
68 Correct 55 ms 14672 KB Output is correct
69 Correct 53 ms 15444 KB Output is correct
70 Correct 49 ms 18268 KB Output is correct
71 Correct 60 ms 14416 KB Output is correct
72 Correct 3 ms 10576 KB Output is correct
73 Correct 2 ms 10576 KB Output is correct
74 Correct 2 ms 10576 KB Output is correct
75 Correct 3 ms 10576 KB Output is correct
76 Correct 2 ms 8528 KB Output is correct
77 Correct 2 ms 10576 KB Output is correct
78 Correct 2 ms 10576 KB Output is correct
79 Correct 2 ms 10576 KB Output is correct
80 Correct 2 ms 10576 KB Output is correct
81 Correct 2 ms 10576 KB Output is correct
82 Correct 2 ms 10576 KB Output is correct
83 Correct 3 ms 10832 KB Output is correct
84 Correct 2 ms 10576 KB Output is correct
85 Correct 2 ms 10832 KB Output is correct
86 Correct 2 ms 10576 KB Output is correct
87 Correct 3 ms 11088 KB Output is correct
88 Correct 2 ms 10576 KB Output is correct
89 Correct 2 ms 10576 KB Output is correct
90 Correct 2 ms 10576 KB Output is correct
91 Correct 3 ms 10832 KB Output is correct
92 Correct 3 ms 10588 KB Output is correct
93 Correct 3 ms 10692 KB Output is correct
94 Correct 2 ms 10588 KB Output is correct
95 Correct 3 ms 10576 KB Output is correct
96 Correct 2 ms 10576 KB Output is correct
97 Correct 2 ms 10576 KB Output is correct
98 Correct 3 ms 10576 KB Output is correct
99 Correct 3 ms 10744 KB Output is correct
100 Correct 3 ms 10576 KB Output is correct
101 Correct 3 ms 10832 KB Output is correct
102 Correct 3 ms 10832 KB Output is correct
103 Correct 3 ms 10688 KB Output is correct
104 Correct 3 ms 10832 KB Output is correct
105 Correct 3 ms 10832 KB Output is correct
106 Correct 3 ms 10832 KB Output is correct
107 Correct 3 ms 10576 KB Output is correct
108 Correct 2 ms 10848 KB Output is correct
109 Correct 3 ms 10576 KB Output is correct
110 Correct 3 ms 10576 KB Output is correct
111 Correct 2 ms 10576 KB Output is correct
112 Correct 2 ms 10576 KB Output is correct
113 Correct 2 ms 10576 KB Output is correct
114 Correct 2 ms 10576 KB Output is correct
115 Correct 2 ms 10576 KB Output is correct
116 Correct 2 ms 10576 KB Output is correct
117 Correct 2 ms 8696 KB Output is correct
118 Correct 2 ms 10576 KB Output is correct
119 Correct 2 ms 10576 KB Output is correct
120 Correct 2 ms 10576 KB Output is correct
121 Correct 2 ms 10576 KB Output is correct
122 Correct 3 ms 10576 KB Output is correct
123 Correct 2 ms 10576 KB Output is correct
124 Correct 2 ms 10832 KB Output is correct
125 Correct 47 ms 28232 KB Output is correct
126 Correct 2 ms 10576 KB Output is correct
127 Correct 2 ms 10832 KB Output is correct
128 Correct 31 ms 27596 KB Output is correct
129 Correct 2 ms 10744 KB Output is correct
130 Correct 3 ms 11088 KB Output is correct
131 Correct 48 ms 28608 KB Output is correct
132 Correct 2 ms 10744 KB Output is correct
133 Correct 2 ms 10576 KB Output is correct
134 Correct 36 ms 14648 KB Output is correct
135 Correct 2 ms 10588 KB Output is correct
136 Correct 3 ms 10832 KB Output is correct
137 Correct 893 ms 20104 KB Output is correct
138 Correct 24 ms 13528 KB Output is correct
139 Correct 3 ms 10576 KB Output is correct
140 Correct 2 ms 10576 KB Output is correct
141 Correct 30 ms 14028 KB Output is correct
142 Correct 28 ms 14212 KB Output is correct
143 Correct 3 ms 10576 KB Output is correct
144 Correct 4 ms 10576 KB Output is correct
145 Correct 28 ms 14452 KB Output is correct
146 Correct 35 ms 14412 KB Output is correct
147 Correct 27 ms 14348 KB Output is correct
148 Correct 2 ms 10576 KB Output is correct
149 Correct 3 ms 10576 KB Output is correct
150 Correct 3 ms 10576 KB Output is correct
151 Correct 3 ms 10576 KB Output is correct
152 Correct 3 ms 10576 KB Output is correct
153 Correct 55 ms 15052 KB Output is correct
154 Correct 61 ms 15176 KB Output is correct
155 Correct 41 ms 17484 KB Output is correct
156 Correct 56 ms 13536 KB Output is correct
157 Correct 49 ms 14428 KB Output is correct
158 Correct 44 ms 21836 KB Output is correct
159 Correct 45 ms 19196 KB Output is correct
160 Correct 3 ms 10832 KB Output is correct
161 Correct 3 ms 10832 KB Output is correct
162 Correct 3 ms 10748 KB Output is correct
163 Correct 3 ms 10832 KB Output is correct
164 Correct 7 ms 11088 KB Output is correct
165 Correct 54 ms 14640 KB Output is correct
166 Correct 54 ms 15696 KB Output is correct
167 Correct 51 ms 18256 KB Output is correct
168 Correct 51 ms 14416 KB Output is correct
169 Correct 3 ms 11000 KB Output is correct
170 Correct 3 ms 10692 KB Output is correct
171 Correct 2 ms 10576 KB Output is correct
172 Correct 3 ms 11000 KB Output is correct
173 Correct 2 ms 10576 KB Output is correct
174 Correct 3 ms 10744 KB Output is correct
175 Correct 2 ms 10576 KB Output is correct
176 Correct 3 ms 10576 KB Output is correct
177 Correct 979 ms 21204 KB Output is correct
178 Correct 308 ms 15440 KB Output is correct
179 Correct 48 ms 13648 KB Output is correct
180 Correct 5 ms 11088 KB Output is correct
181 Correct 25 ms 14028 KB Output is correct
182 Correct 4 ms 11004 KB Output is correct
183 Correct 4 ms 11004 KB Output is correct
184 Correct 4 ms 10832 KB Output is correct
185 Correct 4 ms 10992 KB Output is correct
186 Correct 30 ms 13444 KB Output is correct
187 Correct 32 ms 12852 KB Output is correct
188 Correct 28 ms 13260 KB Output is correct
189 Correct 27 ms 12760 KB Output is correct
190 Correct 29 ms 12884 KB Output is correct
191 Correct 25 ms 12816 KB Output is correct
192 Correct 5 ms 11088 KB Output is correct
193 Correct 31 ms 14068 KB Output is correct
194 Correct 27 ms 16548 KB Output is correct
195 Correct 2 ms 10576 KB Output is correct
196 Correct 2 ms 10576 KB Output is correct
197 Correct 3 ms 10576 KB Output is correct
198 Correct 3 ms 10576 KB Output is correct