Submission #313568

#TimeUsernameProblemLanguageResultExecution timeMemory
313568talant117408Friend (IOI14_friend)C++17
100 / 100
38 ms2304 KiB
#include "friend.h"
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef pair <ll, ll> pii;
 
#define precision(n) fixed << setprecision(n)
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define mp make_pair
#define eps (double)1e-9
#define PI 2*acos(0.0)
#define endl "\n"
#define sz(v) (int)(v).size()
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define do_not_disturb ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

int findSample(int n, int conf[], int host[], int prot[]){
    
    int p[n], q[n];
    for(int i = 0; i < n; i++){
        p[i] = conf[i];
        q[i] = 0;
    }
    
    for(int i = n-1; i; i--){
        int ph = p[host[i]], qh = q[host[i]], pr = p[i], qr = q[i];
        if(!prot[i]){
            p[host[i]] = ph+qr;
            q[host[i]] = max(pr+qh, qh+qr);
        }
        else if(prot[i]&1){
            p[host[i]] = max(ph+qr, max(pr+qh, ph+pr));
            q[host[i]] = qh+qr;
        }
        else{
            p[host[i]] = max(ph+qr, pr+qh);
            q[host[i]] = qh+qr;
        }
    }
    
    return max(p[0], q[0]);     
}
#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...