Skip to content

Instantly share code, notes, and snippets.

@viliml
Created July 4, 2016 13:24
Show Gist options
  • Select an option

  • Save viliml/59ac124813b0223a85aac061b207f39d to your computer and use it in GitHub Desktop.

Select an option

Save viliml/59ac124813b0223a85aac061b207f39d to your computer and use it in GitHub Desktop.
IOI 2014. day 2
#include "friend.h"
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100100;
int take[MAXN], dont[MAXN];
// Find out best sample
int findSample(int n,int confidence[],int host[],int protocol[])
{
int i;
for (i = 0; i < n; ++i)
{
take[i] = confidence[i];
dont[i] = 0;
}
for (i = n - 1; i > 0; --i) switch (protocol[i])
{
case 0:
take[host[i]] += dont[i];
dont[host[i]] += max(take[i], dont[i]);
break;
case 1:
take[host[i]] = max(take[host[i]] + take[i], max(take[host[i]] + dont[i], dont[host[i]] + take[i]));
dont[host[i]] += dont[i];
break;
case 2:
take[host[i]] = max(take[host[i]] + dont[i], dont[host[i]] + take[i]);
dont[host[i]] += dont[i];
break;
}
return max(take[0], dont[0]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment