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 <bits/stdc++.h>
//#include "friend.h"
#define mp make_pair
#define mt make_tuple
#define ff first
#define ss second
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll INFL = (1LL<<62)-1;
const int INF = (1<<30)-1;
const int MAXN = 1001;
int findSample(int n, int confidence[], int host[], int protocol[]){
vector<pii> dp(n); // first -> pegar; second -> não pegar
for(int i = 0; i < n; i++)
dp[i].ff = confidence[i];
for(int i = n-1; i >0; i--){
switch(protocol[i]){
case 0:
dp[host[i]] = {dp[host[i]].ff + dp[i].ss, dp[host[i]].ss + max(dp[i].ff, dp[i].ss)};
break;
case 1:
dp[host[i]] = {max(dp[host[i]].ff + dp[i].ff, max(dp[host[i]].ff + dp[i].ss, dp[host[i]].ss + dp[i].ff)), dp[host[i]].ss + dp[i].ss};
break;
case 2:
dp[host[i]] = {max(dp[host[i]].ff + dp[i].ss, dp[host[i]].ss + dp[i].ff), dp[host[i]].ss + dp[i].ss};
}
}
return max(dp[0].ff, dp[0].ss);
}
# | 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... |