제출 #924929

#제출 시각아이디문제언어결과실행 시간메모리
924929Sir_Ahmed_ImranCat in a tree (BOI17_catinatree)C++17
51 / 100
26 ms17112 KiB
///~~~LOTA~~~/// #include <bits/stdc++.h> using namespace std; #define ll long long #define append push_back #define add insert #define nl "\n" #define ff first #define ss second #define pii pair<int,int> #define all(x) (x).begin(),(x).end() #define L0TA ios_base::sync_with_stdio(false);cin.tie(NULL) #define N 1501 int d; int dp[N][N]; vector<int> a[N]; void dfs(int v){ int m=(d+1)/2; for(auto& j:a[v]){ dfs(j); for(int i=m;i<=d;i++) dp[v][i%d]+=dp[j][i-1]; } for(int i=1;i<m;i++) for(auto& j:a[v]) dp[v][i]=max(dp[v][i],dp[j][i-1]+dp[v][d-i]-dp[j][d-i-1]); dp[v][0]++; for(int i=d;i>0;i--) dp[v][i-1]=max(dp[v][i-1],dp[v][i]); } void solve(){ int n,m; cin>>n>>d; for(int i=1;i<n;i++){ cin>>m; a[m].append(i); } dfs(0); cout<<dp[0][0]<<nl; } int main(){ L0TA; solve(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...