# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
798261 | QwertyPi | Friend (IOI14_friend) | C++14 | 0 ms | 0 KiB |
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;
struct state{
int p, q;
};
state st[100011];
state f(int ptc, state s, state t){
if(ptc == 1) return {s.p + t.q, max(s.q + t.p, s.q + t.q)};
else if(ptc == 2) return {max(s.p + t.p, max(s.p + t.q, s.q + t.p)), s.q + t.q};
else return {max(s.p + t.q, s.q + t.p), s.q + t.q};
}
int findSample(int n, int confidence[], int host[], int protocol[]){
for(int i = 0; i < n; i++) st[i] = {confidence[i], 0};
for(int i = n - 1; i >= 1; i--){
st[host[i]] = f(protocol[i], st[i], st[host[i]]);
}
return ans;
}