답안 #917382

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
917382 2024-01-28T04:19:51 Z abcvuitunggio 참나무 (IOI23_beechtree) C++17
9 / 100
2000 ms 37628 KB
#include "beechtree.h"
#include <bits/stdc++.h>
using namespace std;
int n,m,bad[200001],d[200001],p[200001][20],dp[2001][2001],ch[200001];
vector <pair <int, int>> ke[200001];
vector <int> res;
void dfs(int u){
    for (auto [c,v]:ke[u]){
        dfs(v);
        bad[u]|=bad[v];
    }
}
int lca(int u, int v){
    u++,v++;
    if (d[u]<d[v])
        swap(u,v);
    int x=d[u]-d[v];
    for (int i=0;i<20;i++)
        if ((x>>i)&1)
            u=p[u][i];
    if (u==v)
        return u-1;
    for (int i=19;i>=0;i--)
        if (p[u][i]!=p[v][i]){
            u=p[u][i];
            v=p[v][i];
        }
    return p[u][0]-1;
}
vector <int> beechtree(int N, int M, vector<int> P, vector<int> C){
    n=N,m=M;
    for (int i=1;i<n;i++)
        ke[P[i]].push_back({C[i],i});
    for (int i=0;i<n;i++){
        sort(ke[i].begin(),ke[i].end());
        for (int j=1;j<ke[i].size();j++)
            if (ke[i][j].first==ke[i][j-1].first)
                bad[i]=1;
        p[i+1][0]=P[i]+1;
        d[i+1]=d[P[i]+1]+1;
        for (int j=1;j<20;j++)
            p[i+1][j]=p[p[i+1][j-1]][j-1];
    }
    for (int i=0;i<n;i++)
        for (int j=i+1;j<n;j++){
            int u=i,v=j;
            if (ke[i].size()>ke[j].size())
                swap(u,v);
            for (auto [c,k]:ke[u])
                ch[c]=1;
            int cnt=0;
            for (auto [c,k]:ke[v])
                cnt+=ch[c];
            for (auto [c,k]:ke[u])
                ch[c]=0;
            if (cnt!=ke[u].size()){
                bad[lca(i,j)]=1;
                continue;
            }
            dp[i][j]=(ke[i].size()>ke[j].size()?1:(ke[i].size()<ke[j].size()?-1:0));
            if (!dp[i][j]){
                if (!i)
                    dp[i][j]=1;
                else if (C[i]==C[j])
                    dp[i][j]=dp[P[i]][P[j]];
            }
            if (dp[i][j]<0&&!i)
                bad[0]=1;
            if (dp[i][j]&&dp[i][j]==-dp[P[i]][P[j]]){
                int l=lca(i,j);
                if (l!=i)
                    bad[l]=1;
                else
                    bad[P[l]]=1;
            }
        }
    dfs(0);
    for (int i=0;i<n;i++)
        res.push_back(bad[i]^1);
    return res;
}

Compilation message

beechtree.cpp: In function 'std::vector<int> beechtree(int, int, std::vector<int>, std::vector<int>)':
beechtree.cpp:36:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |         for (int j=1;j<ke[i].size();j++)
      |                      ~^~~~~~~~~~~~~
beechtree.cpp:56:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   56 |             if (cnt!=ke[u].size()){
      |                 ~~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 9052 KB Output is correct
2 Correct 2 ms 8796 KB Output is correct
3 Correct 2 ms 8796 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8796 KB Output is correct
2 Correct 2 ms 8796 KB Output is correct
3 Correct 2 ms 8796 KB Output is correct
4 Correct 3 ms 8792 KB Output is correct
5 Correct 2 ms 8796 KB Output is correct
6 Correct 2 ms 8796 KB Output is correct
7 Correct 2 ms 8796 KB Output is correct
8 Correct 3 ms 8796 KB Output is correct
9 Correct 2 ms 8828 KB Output is correct
10 Correct 2 ms 8820 KB Output is correct
11 Correct 2 ms 8792 KB Output is correct
12 Correct 2 ms 8792 KB Output is correct
13 Correct 2 ms 8796 KB Output is correct
14 Correct 2 ms 8796 KB Output is correct
15 Correct 3 ms 9048 KB Output is correct
16 Correct 2 ms 8796 KB Output is correct
17 Correct 2 ms 8796 KB Output is correct
18 Correct 2 ms 8796 KB Output is correct
19 Correct 2 ms 8796 KB Output is correct
20 Correct 3 ms 8796 KB Output is correct
21 Correct 2 ms 8796 KB Output is correct
22 Correct 2 ms 8796 KB Output is correct
23 Correct 2 ms 8796 KB Output is correct
24 Correct 2 ms 8796 KB Output is correct
25 Correct 2 ms 8796 KB Output is correct
26 Correct 2 ms 8796 KB Output is correct
27 Correct 2 ms 8796 KB Output is correct
28 Correct 2 ms 8796 KB Output is correct
29 Correct 2 ms 8804 KB Output is correct
30 Correct 2 ms 8796 KB Output is correct
31 Correct 2 ms 8796 KB Output is correct
32 Correct 2 ms 8796 KB Output is correct
33 Correct 2 ms 8800 KB Output is correct
34 Correct 2 ms 9048 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8796 KB Output is correct
2 Correct 2 ms 8796 KB Output is correct
3 Correct 2 ms 8796 KB Output is correct
4 Correct 3 ms 8792 KB Output is correct
5 Correct 2 ms 8796 KB Output is correct
6 Correct 2 ms 8796 KB Output is correct
7 Execution timed out 2047 ms 37628 KB Time limit exceeded
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 10840 KB Output is correct
2 Correct 2 ms 10844 KB Output is correct
3 Correct 2 ms 10840 KB Output is correct
4 Correct 2 ms 10844 KB Output is correct
5 Correct 2 ms 10844 KB Output is correct
6 Correct 2 ms 10840 KB Output is correct
7 Correct 2 ms 11096 KB Output is correct
8 Correct 3 ms 10844 KB Output is correct
9 Correct 2 ms 8796 KB Output is correct
10 Correct 2 ms 10868 KB Output is correct
11 Correct 7 ms 19288 KB Output is correct
12 Correct 6 ms 17064 KB Output is correct
13 Correct 7 ms 16988 KB Output is correct
14 Correct 6 ms 17076 KB Output is correct
15 Execution timed out 2077 ms 23304 KB Time limit exceeded
16 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8796 KB Output is correct
2 Correct 2 ms 8796 KB Output is correct
3 Correct 2 ms 8796 KB Output is correct
4 Correct 3 ms 8796 KB Output is correct
5 Execution timed out 2047 ms 37628 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 9052 KB Output is correct
2 Correct 2 ms 8796 KB Output is correct
3 Correct 2 ms 8796 KB Output is correct
4 Correct 2 ms 8796 KB Output is correct
5 Correct 2 ms 8796 KB Output is correct
6 Correct 2 ms 8796 KB Output is correct
7 Correct 3 ms 8792 KB Output is correct
8 Correct 2 ms 8796 KB Output is correct
9 Correct 2 ms 8796 KB Output is correct
10 Correct 2 ms 8796 KB Output is correct
11 Correct 3 ms 8796 KB Output is correct
12 Correct 2 ms 8828 KB Output is correct
13 Correct 2 ms 8820 KB Output is correct
14 Correct 2 ms 8792 KB Output is correct
15 Correct 2 ms 8792 KB Output is correct
16 Correct 2 ms 8796 KB Output is correct
17 Correct 2 ms 8796 KB Output is correct
18 Correct 3 ms 9048 KB Output is correct
19 Correct 2 ms 8796 KB Output is correct
20 Correct 2 ms 8796 KB Output is correct
21 Correct 2 ms 8796 KB Output is correct
22 Correct 2 ms 8796 KB Output is correct
23 Correct 3 ms 8796 KB Output is correct
24 Correct 2 ms 8796 KB Output is correct
25 Correct 2 ms 8796 KB Output is correct
26 Correct 2 ms 8796 KB Output is correct
27 Correct 2 ms 8796 KB Output is correct
28 Correct 2 ms 8796 KB Output is correct
29 Correct 2 ms 8796 KB Output is correct
30 Correct 2 ms 8796 KB Output is correct
31 Correct 2 ms 8796 KB Output is correct
32 Correct 2 ms 8804 KB Output is correct
33 Correct 2 ms 8796 KB Output is correct
34 Correct 2 ms 8796 KB Output is correct
35 Correct 2 ms 8796 KB Output is correct
36 Correct 2 ms 8800 KB Output is correct
37 Correct 2 ms 9048 KB Output is correct
38 Correct 3 ms 10840 KB Output is correct
39 Correct 2 ms 10844 KB Output is correct
40 Correct 2 ms 10840 KB Output is correct
41 Correct 2 ms 10844 KB Output is correct
42 Correct 2 ms 10844 KB Output is correct
43 Correct 2 ms 10840 KB Output is correct
44 Correct 2 ms 11096 KB Output is correct
45 Correct 3 ms 10844 KB Output is correct
46 Correct 2 ms 8796 KB Output is correct
47 Correct 2 ms 10868 KB Output is correct
48 Correct 3 ms 10844 KB Output is correct
49 Correct 3 ms 10844 KB Output is correct
50 Correct 3 ms 10844 KB Output is correct
51 Correct 3 ms 10868 KB Output is correct
52 Correct 3 ms 11100 KB Output is correct
53 Correct 3 ms 10844 KB Output is correct
54 Correct 2 ms 10844 KB Output is correct
55 Incorrect 3 ms 10844 KB 2nd lines differ - on the 82nd token, expected: '0', found: '1'
56 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8796 KB Output is correct
2 Correct 2 ms 8796 KB Output is correct
3 Correct 2 ms 8796 KB Output is correct
4 Correct 3 ms 8796 KB Output is correct
5 Correct 2 ms 8828 KB Output is correct
6 Correct 2 ms 8820 KB Output is correct
7 Correct 2 ms 8792 KB Output is correct
8 Correct 2 ms 8792 KB Output is correct
9 Correct 2 ms 8796 KB Output is correct
10 Correct 2 ms 8796 KB Output is correct
11 Correct 3 ms 9048 KB Output is correct
12 Correct 2 ms 8796 KB Output is correct
13 Correct 2 ms 8796 KB Output is correct
14 Correct 2 ms 8796 KB Output is correct
15 Correct 2 ms 8796 KB Output is correct
16 Correct 3 ms 8796 KB Output is correct
17 Correct 2 ms 8796 KB Output is correct
18 Correct 2 ms 8796 KB Output is correct
19 Correct 2 ms 8796 KB Output is correct
20 Correct 2 ms 8796 KB Output is correct
21 Correct 2 ms 8796 KB Output is correct
22 Correct 2 ms 8796 KB Output is correct
23 Correct 2 ms 8796 KB Output is correct
24 Correct 2 ms 8796 KB Output is correct
25 Correct 18 ms 23156 KB Output is correct
26 Correct 16 ms 23384 KB Output is correct
27 Correct 34 ms 23276 KB Output is correct
28 Correct 80 ms 23260 KB Output is correct
29 Correct 17 ms 23132 KB Output is correct
30 Correct 72 ms 23256 KB Output is correct
31 Correct 16 ms 23132 KB Output is correct
32 Incorrect 25 ms 23260 KB 2nd lines differ - on the 802nd token, expected: '0', found: '1'
33 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 9052 KB Output is correct
2 Correct 2 ms 8796 KB Output is correct
3 Correct 2 ms 8796 KB Output is correct
4 Correct 2 ms 8796 KB Output is correct
5 Correct 2 ms 8796 KB Output is correct
6 Correct 2 ms 8796 KB Output is correct
7 Correct 3 ms 8792 KB Output is correct
8 Correct 2 ms 8796 KB Output is correct
9 Correct 2 ms 8796 KB Output is correct
10 Correct 2 ms 8796 KB Output is correct
11 Correct 3 ms 8796 KB Output is correct
12 Correct 2 ms 8828 KB Output is correct
13 Correct 2 ms 8820 KB Output is correct
14 Correct 2 ms 8792 KB Output is correct
15 Correct 2 ms 8792 KB Output is correct
16 Correct 2 ms 8796 KB Output is correct
17 Correct 2 ms 8796 KB Output is correct
18 Correct 3 ms 9048 KB Output is correct
19 Correct 2 ms 8796 KB Output is correct
20 Correct 2 ms 8796 KB Output is correct
21 Correct 2 ms 8796 KB Output is correct
22 Correct 2 ms 8796 KB Output is correct
23 Correct 3 ms 8796 KB Output is correct
24 Correct 2 ms 8796 KB Output is correct
25 Correct 2 ms 8796 KB Output is correct
26 Correct 2 ms 8796 KB Output is correct
27 Correct 2 ms 8796 KB Output is correct
28 Correct 2 ms 8796 KB Output is correct
29 Correct 2 ms 8796 KB Output is correct
30 Correct 2 ms 8796 KB Output is correct
31 Correct 2 ms 8796 KB Output is correct
32 Correct 2 ms 8804 KB Output is correct
33 Correct 2 ms 8796 KB Output is correct
34 Correct 2 ms 8796 KB Output is correct
35 Correct 2 ms 8796 KB Output is correct
36 Correct 2 ms 8800 KB Output is correct
37 Correct 2 ms 9048 KB Output is correct
38 Correct 3 ms 10844 KB Output is correct
39 Correct 3 ms 10844 KB Output is correct
40 Correct 3 ms 10844 KB Output is correct
41 Correct 3 ms 10868 KB Output is correct
42 Correct 3 ms 10840 KB Output is correct
43 Correct 2 ms 10844 KB Output is correct
44 Correct 2 ms 10840 KB Output is correct
45 Correct 2 ms 10844 KB Output is correct
46 Correct 2 ms 10844 KB Output is correct
47 Correct 2 ms 10840 KB Output is correct
48 Correct 2 ms 11096 KB Output is correct
49 Correct 3 ms 10844 KB Output is correct
50 Correct 2 ms 8796 KB Output is correct
51 Correct 2 ms 10868 KB Output is correct
52 Correct 7 ms 19288 KB Output is correct
53 Correct 6 ms 17064 KB Output is correct
54 Correct 7 ms 16988 KB Output is correct
55 Correct 6 ms 17076 KB Output is correct
56 Correct 3 ms 11100 KB Output is correct
57 Correct 3 ms 10844 KB Output is correct
58 Correct 2 ms 10844 KB Output is correct
59 Incorrect 3 ms 10844 KB 2nd lines differ - on the 82nd token, expected: '0', found: '1'
60 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8796 KB Output is correct
2 Correct 2 ms 8796 KB Output is correct
3 Correct 2 ms 8796 KB Output is correct
4 Correct 3 ms 8796 KB Output is correct
5 Correct 2 ms 8828 KB Output is correct
6 Correct 2 ms 8820 KB Output is correct
7 Correct 2 ms 8792 KB Output is correct
8 Correct 2 ms 8792 KB Output is correct
9 Correct 2 ms 8796 KB Output is correct
10 Correct 2 ms 8796 KB Output is correct
11 Correct 3 ms 9048 KB Output is correct
12 Correct 2 ms 8796 KB Output is correct
13 Correct 2 ms 8796 KB Output is correct
14 Correct 2 ms 8796 KB Output is correct
15 Correct 2 ms 8796 KB Output is correct
16 Correct 3 ms 8796 KB Output is correct
17 Correct 2 ms 8796 KB Output is correct
18 Correct 2 ms 8796 KB Output is correct
19 Correct 2 ms 8796 KB Output is correct
20 Correct 2 ms 8796 KB Output is correct
21 Correct 2 ms 8796 KB Output is correct
22 Correct 2 ms 8796 KB Output is correct
23 Correct 2 ms 8796 KB Output is correct
24 Correct 2 ms 8796 KB Output is correct
25 Correct 18 ms 23156 KB Output is correct
26 Correct 16 ms 23384 KB Output is correct
27 Correct 34 ms 23276 KB Output is correct
28 Correct 80 ms 23260 KB Output is correct
29 Correct 17 ms 23132 KB Output is correct
30 Correct 72 ms 23256 KB Output is correct
31 Correct 16 ms 23132 KB Output is correct
32 Incorrect 25 ms 23260 KB 2nd lines differ - on the 802nd token, expected: '0', found: '1'
33 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 9052 KB Output is correct
2 Correct 2 ms 8796 KB Output is correct
3 Correct 2 ms 8796 KB Output is correct
4 Correct 2 ms 8796 KB Output is correct
5 Correct 2 ms 8796 KB Output is correct
6 Correct 2 ms 8796 KB Output is correct
7 Correct 3 ms 8792 KB Output is correct
8 Correct 2 ms 8796 KB Output is correct
9 Correct 2 ms 8796 KB Output is correct
10 Correct 2 ms 8796 KB Output is correct
11 Correct 3 ms 8796 KB Output is correct
12 Correct 2 ms 8828 KB Output is correct
13 Correct 2 ms 8820 KB Output is correct
14 Correct 2 ms 8792 KB Output is correct
15 Correct 2 ms 8792 KB Output is correct
16 Correct 2 ms 8796 KB Output is correct
17 Correct 2 ms 8796 KB Output is correct
18 Correct 3 ms 9048 KB Output is correct
19 Correct 2 ms 8796 KB Output is correct
20 Correct 2 ms 8796 KB Output is correct
21 Correct 2 ms 8796 KB Output is correct
22 Correct 2 ms 8796 KB Output is correct
23 Correct 3 ms 8796 KB Output is correct
24 Correct 2 ms 8796 KB Output is correct
25 Correct 2 ms 8796 KB Output is correct
26 Correct 2 ms 8796 KB Output is correct
27 Correct 2 ms 8796 KB Output is correct
28 Correct 2 ms 8796 KB Output is correct
29 Correct 2 ms 8796 KB Output is correct
30 Correct 2 ms 8796 KB Output is correct
31 Correct 2 ms 8796 KB Output is correct
32 Correct 2 ms 8804 KB Output is correct
33 Correct 2 ms 8796 KB Output is correct
34 Correct 2 ms 8796 KB Output is correct
35 Correct 2 ms 8796 KB Output is correct
36 Correct 2 ms 8800 KB Output is correct
37 Correct 2 ms 9048 KB Output is correct
38 Execution timed out 2047 ms 37628 KB Time limit exceeded
39 Halted 0 ms 0 KB -