This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "friend.h"
#include <bits/stdc++.h>
using namespace std;
// Find out best sample
int findSample(int n,int confidence[],int host[],int protocol[]){
vector<int> take(n);
vector<int> leave(n);
for (int i = 0; i<n; i++){
take[i]=confidence[i];
}
for (int i = n-1; i>0; i--){
//unmerge elements host[i] and i
int x = i;
int y = host[i];
int takenew, leavenew;
if (protocol[i]==0){
//iamyourfriend
takenew = take[y]+leave[x];
leavenew = max(leave[x]+leave[y], take[x]+leave[y]);
} else if (protocol[i]==1){
//myfriendsareyourfriends
takenew = max(take[x]+take[y], max(take[x]+leave[y], leave[x]+take[y]));
leavenew = leave[x]+leave[y];
} else {
//weareyourfriends
takenew = max(take[x]+leave[y],take[y]+leave[x]);
leavenew = leave[x]+leave[y];
}
take[host[i]] = takenew;
leave[host[i]] = leavenew;
}
return max(take[0],leave[0]);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |