답안 #588520

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
588520 2022-07-03T13:03:07 Z Huy Cat in a tree (BOI17_catinatree) C++17
51 / 100
310 ms 524288 KB
/// no sound please
#include<bits/stdc++.h>
#define int long long
#define pii pair<int,int>
#define pic pair<int,char>
#define fi first
#define se second
/*#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")*/
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ldb = long double;
const ll N = (int)1e9 + 1;
const int maxN = (int)3e5 + 5;
const int mod = 1e9 + 7;
//const int mod = 998244353;
const ll infty = 1e18 + 7;
const int base = (int)4e5;

void InputFile()
{
    //freopen("IELTS.inp","r",stdin);
    //freopen("IELTS.out","w",stdout);
    //freopen("test.out","r",stdin);
}

void FastInput()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
}

int n,d;
vector<vector<int>> adj;

void Read()
{
    cin >> n >> d;
    d = min(d,n);
    adj.resize(n);
    for(int i = 1;i < n;i++)
    {
        int p;
        cin >> p;
        adj[p].push_back(i);
        adj[i].push_back(p);
    }
}

vector<int> dp[maxN];

vector<int> operator+(vector<int> a,vector<int> b)
{
    vector<int> res;
    int sz = min((int)max(a.size(),b.size()+1),d + 1);
    res.resize(sz,0);
    res[0] = a[0];
    for(int i = 1;i < sz;i++)
    {
        if(i - 1 < b.size()) res[i] = max(res[i],b[i-1]);
        if(i < a.size()) res[i] = max(res[i],a[i]);
    }
    for(int i = 0;i < a.size();i++)
    {
        for(int j = 0;j < b.size();j++)
        {
            if(i + j + 1 >= d)
            {
                res[min(i,j+1)] = max(res[min(i,j+1)],a[i] + b[j]);
            }
        }
    }
    return res;
}

void DFS(int u,int p)
{
    dp[u] = {1};
    for(int v : adj[u])
    {
        if(v == p) continue;
        DFS(v,u);
        dp[u] = dp[u] + dp[v];
    }
}

void Solve()
{
    DFS(0,0);

    int res = 0;
    for(int i = 0;i < n;i++)
    {
        for(int j = 0;j < dp[i].size();j++)
        {
            res = max(res,dp[i][j]);
        }
    }
    cout << res;
}

void Debug()
{

}


int32_t main()
{
    FastInput();
    //InputFile();
    //int sub_type;
    //cin >> sub_type;
    //Sieve();
    //Prepare();
    int test;
    //cin >> test;
    test = 1;
    while(test--)
        //for(int prc = 1; prc <= test; prc++)
    {
        Read();
        Solve();
        //Debug();
    }
}

Compilation message

catinatree.cpp: In function 'std::vector<long long int> operator+(std::vector<long long int>, std::vector<long long int>)':
catinatree.cpp:64:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   64 |         if(i - 1 < b.size()) res[i] = max(res[i],b[i-1]);
      |            ~~~~~~^~~~~~~~~~
catinatree.cpp:65:14: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   65 |         if(i < a.size()) res[i] = max(res[i],a[i]);
      |            ~~^~~~~~~~~~
catinatree.cpp:67:21: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   67 |     for(int i = 0;i < a.size();i++)
      |                   ~~^~~~~~~~~~
catinatree.cpp:69:25: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   69 |         for(int j = 0;j < b.size();j++)
      |                       ~~^~~~~~~~~~
catinatree.cpp: In function 'void Solve()':
catinatree.cpp:98:25: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   98 |         for(int j = 0;j < dp[i].size();j++)
      |                       ~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7252 KB Output is correct
2 Correct 4 ms 7252 KB Output is correct
3 Correct 4 ms 7252 KB Output is correct
4 Correct 4 ms 7252 KB Output is correct
5 Correct 4 ms 7252 KB Output is correct
6 Correct 3 ms 7252 KB Output is correct
7 Correct 3 ms 7252 KB Output is correct
8 Correct 3 ms 7252 KB Output is correct
9 Correct 3 ms 7252 KB Output is correct
10 Correct 4 ms 7252 KB Output is correct
11 Correct 4 ms 7304 KB Output is correct
12 Correct 4 ms 7252 KB Output is correct
13 Correct 4 ms 7360 KB Output is correct
14 Correct 6 ms 7252 KB Output is correct
15 Correct 4 ms 7252 KB Output is correct
16 Correct 4 ms 7252 KB Output is correct
17 Correct 4 ms 7252 KB Output is correct
18 Correct 4 ms 7252 KB Output is correct
19 Correct 3 ms 7252 KB Output is correct
20 Correct 3 ms 7252 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7252 KB Output is correct
2 Correct 4 ms 7252 KB Output is correct
3 Correct 4 ms 7252 KB Output is correct
4 Correct 4 ms 7252 KB Output is correct
5 Correct 4 ms 7252 KB Output is correct
6 Correct 3 ms 7252 KB Output is correct
7 Correct 3 ms 7252 KB Output is correct
8 Correct 3 ms 7252 KB Output is correct
9 Correct 3 ms 7252 KB Output is correct
10 Correct 4 ms 7252 KB Output is correct
11 Correct 4 ms 7304 KB Output is correct
12 Correct 4 ms 7252 KB Output is correct
13 Correct 4 ms 7360 KB Output is correct
14 Correct 6 ms 7252 KB Output is correct
15 Correct 4 ms 7252 KB Output is correct
16 Correct 4 ms 7252 KB Output is correct
17 Correct 4 ms 7252 KB Output is correct
18 Correct 4 ms 7252 KB Output is correct
19 Correct 3 ms 7252 KB Output is correct
20 Correct 3 ms 7252 KB Output is correct
21 Correct 11 ms 15956 KB Output is correct
22 Correct 4 ms 7380 KB Output is correct
23 Correct 4 ms 7380 KB Output is correct
24 Correct 4 ms 7380 KB Output is correct
25 Correct 5 ms 7380 KB Output is correct
26 Correct 4 ms 7380 KB Output is correct
27 Correct 4 ms 7380 KB Output is correct
28 Correct 5 ms 7508 KB Output is correct
29 Correct 4 ms 7508 KB Output is correct
30 Correct 4 ms 7508 KB Output is correct
31 Correct 4 ms 7508 KB Output is correct
32 Correct 4 ms 7508 KB Output is correct
33 Correct 5 ms 7508 KB Output is correct
34 Correct 4 ms 7508 KB Output is correct
35 Correct 4 ms 7380 KB Output is correct
36 Correct 5 ms 7508 KB Output is correct
37 Correct 5 ms 7508 KB Output is correct
38 Correct 5 ms 7636 KB Output is correct
39 Correct 5 ms 7764 KB Output is correct
40 Correct 4 ms 7764 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7252 KB Output is correct
2 Correct 4 ms 7252 KB Output is correct
3 Correct 4 ms 7252 KB Output is correct
4 Correct 4 ms 7252 KB Output is correct
5 Correct 4 ms 7252 KB Output is correct
6 Correct 3 ms 7252 KB Output is correct
7 Correct 3 ms 7252 KB Output is correct
8 Correct 3 ms 7252 KB Output is correct
9 Correct 3 ms 7252 KB Output is correct
10 Correct 4 ms 7252 KB Output is correct
11 Correct 4 ms 7304 KB Output is correct
12 Correct 4 ms 7252 KB Output is correct
13 Correct 4 ms 7360 KB Output is correct
14 Correct 6 ms 7252 KB Output is correct
15 Correct 4 ms 7252 KB Output is correct
16 Correct 4 ms 7252 KB Output is correct
17 Correct 4 ms 7252 KB Output is correct
18 Correct 4 ms 7252 KB Output is correct
19 Correct 3 ms 7252 KB Output is correct
20 Correct 3 ms 7252 KB Output is correct
21 Correct 11 ms 15956 KB Output is correct
22 Correct 4 ms 7380 KB Output is correct
23 Correct 4 ms 7380 KB Output is correct
24 Correct 4 ms 7380 KB Output is correct
25 Correct 5 ms 7380 KB Output is correct
26 Correct 4 ms 7380 KB Output is correct
27 Correct 4 ms 7380 KB Output is correct
28 Correct 5 ms 7508 KB Output is correct
29 Correct 4 ms 7508 KB Output is correct
30 Correct 4 ms 7508 KB Output is correct
31 Correct 4 ms 7508 KB Output is correct
32 Correct 4 ms 7508 KB Output is correct
33 Correct 5 ms 7508 KB Output is correct
34 Correct 4 ms 7508 KB Output is correct
35 Correct 4 ms 7380 KB Output is correct
36 Correct 5 ms 7508 KB Output is correct
37 Correct 5 ms 7508 KB Output is correct
38 Correct 5 ms 7636 KB Output is correct
39 Correct 5 ms 7764 KB Output is correct
40 Correct 4 ms 7764 KB Output is correct
41 Correct 75 ms 24652 KB Output is correct
42 Correct 52 ms 17032 KB Output is correct
43 Correct 65 ms 17444 KB Output is correct
44 Correct 58 ms 17500 KB Output is correct
45 Correct 67 ms 17484 KB Output is correct
46 Correct 132 ms 26892 KB Output is correct
47 Correct 132 ms 27728 KB Output is correct
48 Correct 141 ms 27816 KB Output is correct
49 Correct 147 ms 27712 KB Output is correct
50 Correct 56 ms 17300 KB Output is correct
51 Correct 44 ms 17332 KB Output is correct
52 Correct 43 ms 17312 KB Output is correct
53 Correct 98 ms 27324 KB Output is correct
54 Correct 101 ms 27360 KB Output is correct
55 Correct 104 ms 27336 KB Output is correct
56 Correct 6 ms 7764 KB Output is correct
57 Correct 260 ms 317116 KB Output is correct
58 Runtime error 310 ms 524288 KB Execution killed with signal 9
59 Halted 0 ms 0 KB -