제출 #542346

#제출 시각아이디문제언어결과실행 시간메모리
542346Sho10Friend (IOI14_friend)C++17
100 / 100
28 ms3360 KiB
#include <bits/stdc++.h> //Andrei Alexandru a.k.a Sho #include "friend.h" using ll=long long; using ld=long double; int const INF=1000000005; ll const LINF=1000000000000000005; ll const mod=1000000007; ld const PI=3.14159265359; #pragma GCC optimize("O3") #pragma GCC optimize("Ofast") #define f first #define s second #define pb push_back #define mp make_pair #define endl '\n' #define CODE_START ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); using namespace std; pair<int,int>dp[100005]; int findSample(int n,int confidence[],int host[],int protocol[]){ for(int i=0;i<n;i++) { dp[i]=mp(0,confidence[i]); } for(int i=n-1;i>=1;i--) { int par=host[i]; if(protocol[i]==0){ dp[par].f=dp[par].f+dp[i].s; dp[par].s=dp[par].s+dp[i].f; }else if(protocol[i]==1){ dp[par].f+=dp[i].f; dp[par].s+=dp[i].s; }else { dp[par].s=max(dp[par].f+dp[i].s,dp[par].s+dp[i].f); dp[par].f+=dp[i].f; } dp[par].s=max(dp[par].s,dp[par].f); } return dp[0].s; } /* int32_t main(){ int n=6; int a[15],b[15],c[15]; a[1]=0; a[2]=0; a[3]=1; a[4]=2; a[5]=0; b[0]=13; b[1]=3; b[2]=6; b[3]=20; b[4]=10; b[5]=15; c[1]=0; c[2]=1; c[3]=2; c[4]=1; c[5]=0; cout<<findSample(n,b,a,c)<<endl; } */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...