Submission #1105988

# Submission time Handle Problem Language Result Execution time Memory
1105988 2024-10-28T16:09:42 Z underwaterkillerwhale Team Coding (EGOI24_teamcoding) C++17
100 / 100
948 ms 29776 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 = 250;

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 10576 KB Output is correct
7 Correct 2 ms 10576 KB Output is correct
8 Correct 2 ms 10996 KB Output is correct
9 Correct 47 ms 29200 KB Output is correct
10 Correct 2 ms 10576 KB Output is correct
11 Correct 2 ms 11088 KB Output is correct
12 Correct 31 ms 28356 KB Output is correct
13 Correct 2 ms 10576 KB Output is correct
14 Correct 3 ms 10996 KB Output is correct
15 Correct 54 ms 29776 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 3 ms 10820 KB Output is correct
4 Correct 3 ms 11088 KB Output is correct
5 Correct 41 ms 28284 KB Output is correct
6 Correct 2 ms 10728 KB Output is correct
7 Correct 3 ms 10832 KB Output is correct
8 Correct 43 ms 15440 KB Output is correct
9 Correct 2 ms 10576 KB Output is correct
10 Correct 3 ms 10832 KB Output is correct
11 Correct 924 ms 20696 KB Output is correct
12 Correct 27 ms 13784 KB Output is correct
13 Correct 2 ms 10576 KB Output is correct
14 Correct 2 ms 10680 KB Output is correct
15 Correct 28 ms 14796 KB Output is correct
16 Correct 27 ms 14812 KB Output is correct
17 Correct 2 ms 10576 KB Output is correct
18 Correct 3 ms 10832 KB Output is correct
19 Correct 25 ms 15108 KB Output is correct
20 Correct 28 ms 15192 KB Output is correct
21 Correct 28 ms 15112 KB Output is correct
22 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 10688 KB Output is correct
3 Correct 3 ms 10900 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 53 ms 29420 KB Output is correct
9 Correct 2 ms 10576 KB Output is correct
10 Correct 4 ms 11344 KB Output is correct
11 Correct 54 ms 29768 KB Output is correct
12 Correct 2 ms 10576 KB Output is correct
13 Correct 3 ms 10576 KB Output is correct
14 Correct 2 ms 10576 KB Output is correct
15 Correct 3 ms 10832 KB Output is correct
16 Correct 3 ms 11000 KB Output is correct
17 Correct 3 ms 10832 KB Output is correct
18 Correct 58 ms 16208 KB Output is correct
19 Correct 58 ms 16472 KB Output is correct
20 Correct 41 ms 18680 KB Output is correct
21 Correct 50 ms 14672 KB Output is correct
22 Correct 58 ms 15696 KB Output is correct
23 Correct 54 ms 23120 KB Output is correct
24 Correct 52 ms 20484 KB Output is correct
25 Correct 3 ms 10832 KB Output is correct
26 Correct 3 ms 10992 KB Output is correct
27 Correct 3 ms 10832 KB Output is correct
28 Correct 3 ms 10832 KB Output is correct
29 Correct 7 ms 11088 KB Output is correct
30 Correct 55 ms 15696 KB Output is correct
31 Correct 59 ms 16712 KB Output is correct
32 Correct 52 ms 19500 KB Output is correct
33 Correct 55 ms 15440 KB Output is correct
34 Correct 3 ms 10744 KB Output is correct
35 Correct 2 ms 10576 KB Output is correct
36 Correct 2 ms 10576 KB Output is correct
37 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 10576 KB Output is correct
7 Correct 2 ms 10576 KB Output is correct
8 Correct 2 ms 11088 KB Output is correct
9 Correct 2 ms 10724 KB Output is correct
10 Correct 3 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 10832 KB Output is correct
15 Correct 2 ms 10576 KB Output is correct
16 Correct 3 ms 10832 KB Output is correct
17 Correct 2 ms 10576 KB Output is correct
18 Correct 2 ms 10576 KB Output is correct
19 Correct 2 ms 10576 KB Output is correct
20 Correct 2 ms 10832 KB Output is correct
21 Correct 2 ms 10748 KB Output is correct
22 Correct 2 ms 10576 KB Output is correct
23 Correct 3 ms 11000 KB Output is correct
24 Correct 3 ms 10740 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 10832 KB Output is correct
28 Correct 3 ms 10832 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 10688 KB Output is correct
33 Correct 3 ms 10832 KB Output is correct
34 Correct 2 ms 10708 KB Output is correct
35 Correct 2 ms 10576 KB Output is correct
36 Correct 3 ms 10576 KB Output is correct
37 Correct 2 ms 10832 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 10576 KB Output is correct
7 Correct 2 ms 10576 KB Output is correct
8 Correct 2 ms 10996 KB Output is correct
9 Correct 47 ms 29200 KB Output is correct
10 Correct 2 ms 10576 KB Output is correct
11 Correct 2 ms 11088 KB Output is correct
12 Correct 31 ms 28356 KB Output is correct
13 Correct 2 ms 10576 KB Output is correct
14 Correct 3 ms 10996 KB Output is correct
15 Correct 54 ms 29776 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 3 ms 10820 KB Output is correct
20 Correct 3 ms 11088 KB Output is correct
21 Correct 41 ms 28284 KB Output is correct
22 Correct 2 ms 10728 KB Output is correct
23 Correct 3 ms 10832 KB Output is correct
24 Correct 43 ms 15440 KB Output is correct
25 Correct 2 ms 10576 KB Output is correct
26 Correct 3 ms 10832 KB Output is correct
27 Correct 924 ms 20696 KB Output is correct
28 Correct 27 ms 13784 KB Output is correct
29 Correct 2 ms 10576 KB Output is correct
30 Correct 2 ms 10680 KB Output is correct
31 Correct 28 ms 14796 KB Output is correct
32 Correct 27 ms 14812 KB Output is correct
33 Correct 2 ms 10576 KB Output is correct
34 Correct 3 ms 10832 KB Output is correct
35 Correct 25 ms 15108 KB Output is correct
36 Correct 28 ms 15192 KB Output is correct
37 Correct 28 ms 15112 KB Output is correct
38 Correct 2 ms 10576 KB Output is correct
39 Correct 2 ms 8528 KB Output is correct
40 Correct 2 ms 10688 KB Output is correct
41 Correct 3 ms 10900 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 53 ms 29420 KB Output is correct
47 Correct 2 ms 10576 KB Output is correct
48 Correct 4 ms 11344 KB Output is correct
49 Correct 54 ms 29768 KB Output is correct
50 Correct 2 ms 10576 KB Output is correct
51 Correct 3 ms 10576 KB Output is correct
52 Correct 2 ms 10576 KB Output is correct
53 Correct 3 ms 10832 KB Output is correct
54 Correct 3 ms 11000 KB Output is correct
55 Correct 3 ms 10832 KB Output is correct
56 Correct 58 ms 16208 KB Output is correct
57 Correct 58 ms 16472 KB Output is correct
58 Correct 41 ms 18680 KB Output is correct
59 Correct 50 ms 14672 KB Output is correct
60 Correct 58 ms 15696 KB Output is correct
61 Correct 54 ms 23120 KB Output is correct
62 Correct 52 ms 20484 KB Output is correct
63 Correct 3 ms 10832 KB Output is correct
64 Correct 3 ms 10992 KB Output is correct
65 Correct 3 ms 10832 KB Output is correct
66 Correct 3 ms 10832 KB Output is correct
67 Correct 7 ms 11088 KB Output is correct
68 Correct 55 ms 15696 KB Output is correct
69 Correct 59 ms 16712 KB Output is correct
70 Correct 52 ms 19500 KB Output is correct
71 Correct 55 ms 15440 KB Output is correct
72 Correct 3 ms 10744 KB Output is correct
73 Correct 2 ms 10576 KB Output is correct
74 Correct 2 ms 10576 KB Output is correct
75 Correct 2 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 2 ms 11088 KB Output is correct
84 Correct 2 ms 10724 KB Output is correct
85 Correct 3 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 10832 KB Output is correct
90 Correct 2 ms 10576 KB Output is correct
91 Correct 3 ms 10832 KB Output is correct
92 Correct 2 ms 10576 KB Output is correct
93 Correct 2 ms 10576 KB Output is correct
94 Correct 2 ms 10576 KB Output is correct
95 Correct 2 ms 10832 KB Output is correct
96 Correct 2 ms 10748 KB Output is correct
97 Correct 2 ms 10576 KB Output is correct
98 Correct 3 ms 11000 KB Output is correct
99 Correct 3 ms 10740 KB Output is correct
100 Correct 3 ms 10832 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 10832 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 10688 KB Output is correct
108 Correct 3 ms 10832 KB Output is correct
109 Correct 2 ms 10708 KB Output is correct
110 Correct 2 ms 10576 KB Output is correct
111 Correct 3 ms 10576 KB Output is correct
112 Correct 2 ms 10832 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 8540 KB Output is correct
118 Correct 2 ms 10728 KB Output is correct
119 Correct 2 ms 10576 KB Output is correct
120 Correct 2 ms 10724 KB Output is correct
121 Correct 2 ms 10576 KB Output is correct
122 Correct 2 ms 10576 KB Output is correct
123 Correct 2 ms 10576 KB Output is correct
124 Correct 3 ms 11088 KB Output is correct
125 Correct 51 ms 29392 KB Output is correct
126 Correct 3 ms 10576 KB Output is correct
127 Correct 3 ms 11088 KB Output is correct
128 Correct 32 ms 28384 KB Output is correct
129 Correct 2 ms 10744 KB Output is correct
130 Correct 3 ms 10996 KB Output is correct
131 Correct 55 ms 29772 KB Output is correct
132 Correct 2 ms 10744 KB Output is correct
133 Correct 3 ms 10832 KB Output is correct
134 Correct 30 ms 15312 KB Output is correct
135 Correct 2 ms 10576 KB Output is correct
136 Correct 3 ms 10936 KB Output is correct
137 Correct 948 ms 20852 KB Output is correct
138 Correct 22 ms 13784 KB Output is correct
139 Correct 3 ms 10744 KB Output is correct
140 Correct 2 ms 10576 KB Output is correct
141 Correct 26 ms 14820 KB Output is correct
142 Correct 27 ms 14804 KB Output is correct
143 Correct 2 ms 10576 KB Output is correct
144 Correct 3 ms 10832 KB Output is correct
145 Correct 27 ms 15116 KB Output is correct
146 Correct 27 ms 15184 KB Output is correct
147 Correct 26 ms 15116 KB Output is correct
148 Correct 2 ms 10576 KB Output is correct
149 Correct 2 ms 10576 KB Output is correct
150 Correct 3 ms 10832 KB Output is correct
151 Correct 3 ms 11004 KB Output is correct
152 Correct 3 ms 11084 KB Output is correct
153 Correct 55 ms 16200 KB Output is correct
154 Correct 52 ms 16200 KB Output is correct
155 Correct 45 ms 18508 KB Output is correct
156 Correct 55 ms 14508 KB Output is correct
157 Correct 65 ms 15696 KB Output is correct
158 Correct 59 ms 23112 KB Output is correct
159 Correct 60 ms 20304 KB Output is correct
160 Correct 3 ms 11004 KB Output is correct
161 Correct 3 ms 10832 KB Output is correct
162 Correct 3 ms 10832 KB Output is correct
163 Correct 3 ms 10832 KB Output is correct
164 Correct 6 ms 11088 KB Output is correct
165 Correct 55 ms 15696 KB Output is correct
166 Correct 53 ms 16720 KB Output is correct
167 Correct 55 ms 19500 KB Output is correct
168 Correct 61 ms 15440 KB Output is correct
169 Correct 4 ms 10832 KB Output is correct
170 Correct 3 ms 10832 KB Output is correct
171 Correct 3 ms 10576 KB Output is correct
172 Correct 3 ms 10832 KB Output is correct
173 Correct 3 ms 10576 KB Output is correct
174 Correct 3 ms 10576 KB Output is correct
175 Correct 3 ms 10576 KB Output is correct
176 Correct 2 ms 10832 KB Output is correct
177 Correct 903 ms 22264 KB Output is correct
178 Correct 319 ms 16504 KB Output is correct
179 Correct 52 ms 14928 KB Output is correct
180 Correct 4 ms 11088 KB Output is correct
181 Correct 26 ms 14792 KB Output is correct
182 Correct 5 ms 11256 KB Output is correct
183 Correct 5 ms 10832 KB Output is correct
184 Correct 5 ms 11088 KB Output is correct
185 Correct 4 ms 10832 KB Output is correct
186 Correct 29 ms 14092 KB Output is correct
187 Correct 27 ms 13528 KB Output is correct
188 Correct 29 ms 14020 KB Output is correct
189 Correct 34 ms 13528 KB Output is correct
190 Correct 29 ms 13484 KB Output is correct
191 Correct 24 ms 13584 KB Output is correct
192 Correct 5 ms 11088 KB Output is correct
193 Correct 26 ms 14964 KB Output is correct
194 Correct 27 ms 17500 KB Output is correct
195 Correct 2 ms 10748 KB Output is correct
196 Correct 2 ms 10576 KB Output is correct
197 Correct 2 ms 10576 KB Output is correct
198 Correct 2 ms 10576 KB Output is correct