제출 #588520

#제출 시각아이디문제언어결과실행 시간메모리
588520HuyCat in a tree (BOI17_catinatree)C++17
51 / 100
310 ms524288 KiB
/// 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(); } }

컴파일 시 표준 에러 (stderr) 메시지

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++)
      |                       ~~^~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...