This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// ~ Be Name Khoda ~ //
#include "friend.h"
#include <bits/stdc++.h>
//#pragma GCC optimize ("O3")
//#pragma GCC target("avx2")
//#pragma GCC optimize("unroll-loops,Ofast")
using namespace std;
typedef long long ll;
#define pb push_back
#define mp make_pair
#define all(x) x.begin(), x.end()
#define fi first
#define se second
const int maxn = 1e6 + 10;
const int maxn5 = 5e5 + 10;
const int maxnt = 1.2e6 + 10;
const int maxn3 = 1e3 + 10;
const int mod = 1e9 + 7;
const ll inf = 1e18;
int hs[maxn5], ty[maxn5];
int n;
ll dp[maxn5][2];
// Find out best sample
int findSample(int n,int confidence[], int host[], int protocol[]){
::n = n;
for(int i = 1; i < n; i++){
dp[i][1] = confidence[i];
hs[i] = host[i];
ty[i] = protocol[i];
}
dp[0][1] = confidence[0];
for(int i = n - 1; i; i--){
if(ty[i] == 0){
dp[hs[i]][0] += max(dp[i][0], dp[i][1]);
dp[hs[i]][1] += dp[i][0];
}
if(ty[i] == 1){
dp[hs[i]][1] = max(dp[hs[i]][1] + max(dp[i][1], dp[i][0]), dp[hs[i]][0] + dp[i][1]);
dp[hs[i]][0] += dp[i][0];
}
if(ty[i] == 2){
dp[hs[i]][1] = max(dp[hs[i]][1] + dp[i][0], dp[i][1] + dp[hs[i]][0]);
dp[hs[i]][0] += dp[i][0];
}
//cout << i << ' ' << ty[i] << ' ' << dp[i][0] << ' ' << dp[i][1] << ' ' << dp[hs[i]][0] << ' ' << dp[hs[i]][1] << endl;
}
return max(dp[0][0], dp[0][1]);
}
# | 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... |