Submission #1044173

# Submission time Handle Problem Language Result Execution time Memory
1044173 2024-08-05T07:50:06 Z 구재현 (European Bad Bitch)(#11065) Team Coding (EGOI24_teamcoding) C++17
31 / 100
2836 ms 27984 KB
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using pi = array<int, 2>;
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
#define cr(v, n) (v).clear(), (v).resize(n);
const int MAXN = 100005;
const int B = 100;

vector<int> gph[MAXN];
int a[MAXN], dep[MAXN], far[MAXN];

vector<int> ds[MAXN];

int hcnt[MAXN][105], ans[MAXN];

int din[MAXN], dout[MAXN], piv;

vector<pi> occ[MAXN];

void dfs(int x)
{
    din[x] = piv++;
    far[x] = dep[x];
    for(auto &y : gph[x])
    {
        dep[y] = dep[x] + 1;
        dfs(y);
        far[x] = max(far[x], far[y]);
    }
    dout[x] = piv;
}

void solve(int x)
{
    for(auto &y : gph[x])
    {
        solve(y);
        if(sz(ds[x])< sz(ds[y]))
        {
            swap(ds[x], ds[y]);
        }
        for(int i = 0; i< sz(ds[y]); i++)
        {
            ds[x][i + sz(ds[x]) - sz(ds[y])] += ds[y][i];
        }
    }
    ds[x].push_back(1);
    for(auto &[y, d] : occ[a[x]])
    {
        if(y <dep[x]) break;
        int idx = y - dep[x];
        ans[x] += min(ds[x][sz(ds[x]) - 1 - idx], d);
    }
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, k;
    cin >> n >>k;
    for(int i = 0; i < n; i++)cin >> a[i];
    for(int i = 0; i< n-1; i++)
    {
        int p;
        cin >> p;
        gph[p].push_back(1+i);
    }
    dfs(0);
    {
        vector<pi> v;
        for(int i = 0; i< n; i++)
        {
            v.push_back({a[i], -dep[i]});
        }
        sort(all(v));
        for(int i = 0; i< sz(v); )
        {
            int j = i;
            while(j < sz(v)&& v[j] == v[i]) j++;
            occ[v[i][0]].push_back({-v[i][1], j - i});
            i = j;
        }
    }
    solve(0);
    {
        vector<pi> v;
        for(int i = 0; i < n; i++)
        {
            v.push_back({a[i], din[i]});
        }
        sort(all(v));
        pi dap{-1, -1};
        for(int i = 0; i< n; i++)
        {
            int opt = ans[i];
            int cur = lower_bound(all(v), pi{a[i], dout[i]}) - lower_bound(all(v), pi{a[i], din[i]});
            dap = max(dap, pi{opt, cur});
        }
        cout <<dap[0] <<" "<< dap[0]-dap[1] <<"\n";

    }
    }
# Verdict Execution time Memory Grader output
1 Correct 2 ms 11868 KB Output is correct
2 Correct 2 ms 11868 KB Output is correct
3 Correct 2 ms 11864 KB Output is correct
4 Correct 2 ms 11868 KB Output is correct
5 Correct 2 ms 11868 KB Output is correct
6 Correct 2 ms 11868 KB Output is correct
7 Correct 2 ms 11868 KB Output is correct
8 Correct 2 ms 12124 KB Output is correct
9 Correct 60 ms 27676 KB Output is correct
10 Correct 2 ms 11868 KB Output is correct
11 Correct 3 ms 12124 KB Output is correct
12 Correct 2836 ms 26608 KB Output is correct
13 Correct 2 ms 11864 KB Output is correct
14 Correct 3 ms 12124 KB Output is correct
15 Correct 61 ms 27984 KB Output is correct
16 Correct 2 ms 11864 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 11864 KB Output is correct
2 Correct 2 ms 11928 KB Output is correct
3 Correct 2 ms 11868 KB Output is correct
4 Correct 4 ms 12256 KB Output is correct
5 Correct 2775 ms 26640 KB Output is correct
6 Correct 2 ms 11868 KB Output is correct
7 Correct 2 ms 11868 KB Output is correct
8 Correct 45 ms 17600 KB Output is correct
9 Correct 2 ms 11868 KB Output is correct
10 Correct 3 ms 12092 KB Output is correct
11 Correct 2831 ms 22412 KB Output is correct
12 Correct 32 ms 17484 KB Output is correct
13 Correct 2 ms 11868 KB Output is correct
14 Correct 2 ms 11868 KB Output is correct
15 Correct 62 ms 17800 KB Output is correct
16 Correct 66 ms 17780 KB Output is correct
17 Correct 2 ms 11868 KB Output is correct
18 Correct 2 ms 11868 KB Output is correct
19 Correct 61 ms 17736 KB Output is correct
20 Correct 70 ms 17592 KB Output is correct
21 Correct 59 ms 17640 KB Output is correct
22 Correct 2 ms 11864 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 11868 KB Output is correct
2 Correct 2 ms 11868 KB Output is correct
3 Correct 2 ms 11868 KB Output is correct
4 Correct 2 ms 11864 KB Output is correct
5 Correct 2 ms 11868 KB Output is correct
6 Correct 2 ms 11868 KB Output is correct
7 Correct 2 ms 11868 KB Output is correct
8 Correct 61 ms 27484 KB Output is correct
9 Correct 2 ms 11868 KB Output is correct
10 Correct 2 ms 12124 KB Output is correct
11 Correct 60 ms 27804 KB Output is correct
12 Correct 2 ms 11864 KB Output is correct
13 Correct 1 ms 11868 KB Output is correct
14 Correct 2 ms 11868 KB Output is correct
15 Correct 3 ms 11988 KB Output is correct
16 Correct 2 ms 11868 KB Output is correct
17 Correct 2 ms 11872 KB Output is correct
18 Incorrect 69 ms 19668 KB Output isn't correct
19 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 11868 KB Output is correct
2 Correct 2 ms 11868 KB Output is correct
3 Correct 2 ms 11868 KB Output is correct
4 Correct 2 ms 11868 KB Output is correct
5 Correct 2 ms 11868 KB Output is correct
6 Correct 2 ms 11868 KB Output is correct
7 Correct 2 ms 11868 KB Output is correct
8 Correct 2 ms 12124 KB Output is correct
9 Correct 1 ms 11868 KB Output is correct
10 Correct 3 ms 12124 KB Output is correct
11 Correct 2 ms 11980 KB Output is correct
12 Correct 3 ms 12124 KB Output is correct
13 Correct 1 ms 11868 KB Output is correct
14 Correct 3 ms 11868 KB Output is correct
15 Correct 2 ms 11928 KB Output is correct
16 Correct 3 ms 12124 KB Output is correct
17 Correct 2 ms 11960 KB Output is correct
18 Correct 2 ms 11868 KB Output is correct
19 Correct 2 ms 11868 KB Output is correct
20 Correct 2 ms 11868 KB Output is correct
21 Correct 2 ms 11868 KB Output is correct
22 Correct 2 ms 11868 KB Output is correct
23 Correct 2 ms 11868 KB Output is correct
24 Correct 3 ms 11972 KB Output is correct
25 Correct 3 ms 11868 KB Output is correct
26 Correct 3 ms 12124 KB Output is correct
27 Correct 3 ms 12120 KB Output is correct
28 Correct 3 ms 11864 KB Output is correct
29 Incorrect 3 ms 11928 KB Output isn't correct
30 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 11868 KB Output is correct
2 Correct 2 ms 11868 KB Output is correct
3 Correct 2 ms 11864 KB Output is correct
4 Correct 2 ms 11868 KB Output is correct
5 Correct 2 ms 11868 KB Output is correct
6 Correct 2 ms 11868 KB Output is correct
7 Correct 2 ms 11868 KB Output is correct
8 Correct 2 ms 12124 KB Output is correct
9 Correct 60 ms 27676 KB Output is correct
10 Correct 2 ms 11868 KB Output is correct
11 Correct 3 ms 12124 KB Output is correct
12 Correct 2836 ms 26608 KB Output is correct
13 Correct 2 ms 11864 KB Output is correct
14 Correct 3 ms 12124 KB Output is correct
15 Correct 61 ms 27984 KB Output is correct
16 Correct 2 ms 11864 KB Output is correct
17 Correct 2 ms 11864 KB Output is correct
18 Correct 2 ms 11928 KB Output is correct
19 Correct 2 ms 11868 KB Output is correct
20 Correct 4 ms 12256 KB Output is correct
21 Correct 2775 ms 26640 KB Output is correct
22 Correct 2 ms 11868 KB Output is correct
23 Correct 2 ms 11868 KB Output is correct
24 Correct 45 ms 17600 KB Output is correct
25 Correct 2 ms 11868 KB Output is correct
26 Correct 3 ms 12092 KB Output is correct
27 Correct 2831 ms 22412 KB Output is correct
28 Correct 32 ms 17484 KB Output is correct
29 Correct 2 ms 11868 KB Output is correct
30 Correct 2 ms 11868 KB Output is correct
31 Correct 62 ms 17800 KB Output is correct
32 Correct 66 ms 17780 KB Output is correct
33 Correct 2 ms 11868 KB Output is correct
34 Correct 2 ms 11868 KB Output is correct
35 Correct 61 ms 17736 KB Output is correct
36 Correct 70 ms 17592 KB Output is correct
37 Correct 59 ms 17640 KB Output is correct
38 Correct 2 ms 11864 KB Output is correct
39 Correct 2 ms 11868 KB Output is correct
40 Correct 2 ms 11868 KB Output is correct
41 Correct 2 ms 11868 KB Output is correct
42 Correct 2 ms 11864 KB Output is correct
43 Correct 2 ms 11868 KB Output is correct
44 Correct 2 ms 11868 KB Output is correct
45 Correct 2 ms 11868 KB Output is correct
46 Correct 61 ms 27484 KB Output is correct
47 Correct 2 ms 11868 KB Output is correct
48 Correct 2 ms 12124 KB Output is correct
49 Correct 60 ms 27804 KB Output is correct
50 Correct 2 ms 11864 KB Output is correct
51 Correct 1 ms 11868 KB Output is correct
52 Correct 2 ms 11868 KB Output is correct
53 Correct 3 ms 11988 KB Output is correct
54 Correct 2 ms 11868 KB Output is correct
55 Correct 2 ms 11872 KB Output is correct
56 Incorrect 69 ms 19668 KB Output isn't correct
57 Halted 0 ms 0 KB -