Submission #494851

#TimeUsernameProblemLanguageResultExecution timeMemory
494851TeaTimeFriend (IOI14_friend)C++17
100 / 100
23 ms3020 KiB
#include <iostream> #include <string> #include <algorithm> #include <vector> #include <set> #include <tuple> #include <map> #include <queue> using namespace std; typedef long long ll; typedef long double ld; #define fastInp cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0); const ll SZ = 2e5 + 100; ll dp[SZ][2], svd[SZ][2]; // 0 for dont take, 1 for take //int confidence[SZ], host[SZ], protocol[SZ]; int findSample(int n, int confidence[], int host[], int protocol[]) { for (int i = n - 1; i >= 0; i--) dp[i][1] += confidence[i]; for (int i = n - 1; i >= 0; i--) { dp[i][1] = max(dp[i][1], dp[i][0]); if (i == 0) continue; if (protocol[i] == 0) { dp[host[i]][0] += dp[i][1]; dp[host[i]][1] += dp[i][0]; dp[host[i]][1] = max(dp[host[i]][1], dp[host[i]][0]); } else if (protocol[i] == 1) { ll sv = dp[host[i]][0]; dp[host[i]][0] += dp[i][0]; dp[host[i]][1] += dp[i][1]; dp[host[i]][1] = max(dp[host[i]][1], sv + dp[i][1]); dp[host[i]][1] = max(dp[host[i]][1], dp[host[i]][0]); } else { ll sv = dp[host[i]][0]; dp[host[i]][0] += dp[i][0]; dp[host[i]][1] = max(dp[host[i]][1] + dp[i][0], sv + dp[i][1]); } } return dp[0][1]; }
#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...