Submission #392886

#TimeUsernameProblemLanguageResultExecution timeMemory
392886Aldas25Friend (IOI14_friend)C++14
100 / 100
32 ms4548 KiB
#include "friend.h" #include <bits/stdc++.h> using namespace std; #define FOR(i, a, b) for (int i = (a); i <= (b); i++) #define REP(n) FOR(O, 1, (n)) #define f first #define s second #define pb push_back typedef pair<int, int> pii; typedef vector<int> vi; typedef vector<pii> vii; const int MAXN = 100100; int n; int conf[MAXN], h[MAXN], prot[MAXN]; int dp[MAXN][2]; int findSample(int N,int confidence[],int host[],int protocol[]){ n = N; FOR(i, 0, n-1) conf[i] = confidence[i]; FOR(i, 1, n-1) h[i] = host[i], prot[i] = protocol[i]; FOR(i, 0, n-1) dp[i][1] = conf[i]; for (int i = n-1; i > 0; i--) { int x = h[i], y = i; if (prot[i] == 0) { /// I am your friend dp[x][1] += dp[y][0]; dp[x][0] += max(dp[y][0], dp[y][1]); } else if (prot[i] == 1) { /// My friends are your friends dp[x][1] += max(dp[y][0], dp[y][1]); dp[x][1] = max(dp[x][1], dp[x][0] + dp[y][1]); dp[x][0] += dp[y][0]; } else { /// We are your friends dp[x][1] = max(dp[x][1] + dp[y][0], dp[x][0] + dp[y][1]); dp[x][0] += dp[y][0]; } } return max(dp[0][0], 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...