제출 #1027647

#제출 시각아이디문제언어결과실행 시간메모리
1027647dozer친구 (IOI14_friend)C++14
11 / 100
1097 ms3164 KiB
#define __MAXSIZE__ 100002
#include "friend.h"
#include <bits/stdc++.h>
using namespace std;
#define sp " "
#define endl "\n"
#define pb push_back
#define pii pair<int, int>
#define st first
#define nd second
#define mid (l + r) / 2
#define LL node * 2
#define RR node * 2 + 1
#define fileio() freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)
#define fastio() cin.tie(0), ios_base::sync_with_stdio(0)
#define ll long long
#define MAXN 200005


const int modulo = 1e9+7;
const ll INF = 2e18 + 7;

int adj[MAXN];


// Find out best sample
int findSample(int n,int confidence[],int host[],int protocol[]){
	int ans=0;
	vector<int> roots;
	roots.pb(0);
	for (int i = 0; i < n; i++){
		adj[i] = 0;
	}
	for (int i = 1; i < n; i++){
		if (protocol[i] == 0) {
			adj[i] = (1<<host[i]);
			adj[host[i]] |= (1<<i);
		}
		else if (protocol[i] == 1){
			adj[i] = adj[host[i]];
			for (int j = 0; j < i; j++)
				if (adj[host[i]] & (1<<j)) adj[j] |= (1<<i);
		}
		else {
			adj[i] = adj[host[i]] | (1<<host[i]);
			for (int j = 0; j < i; j++)
				if (adj[host[i]] & (1<<j)) adj[j] |= (1<<i);
			adj[host[i]] |= (1<<i);
		}
	}


	for (int i = 1; i < (1<<n); i++){
		int mask = 0;
		int sum = 0;
		for (int j = 0; j < n; j++){
			if (i & (1<<j)) mask |= adj[j], sum += confidence[j];
		}
		if (mask & i) continue;

		ans = max(ans, sum);
	}
	return ans;
}

/*
// Confidence
int confidence[__MAXSIZE__];

// Host
int host[__MAXSIZE__];

// Protocol
int protocol[__MAXSIZE__];

// Main
int main(void)
{
	fileio();
	int n,i;

	// Number of people
	assert(scanf("%d",&n)==1);
	
	// Confidence
	for(i=0;i<n;i++)
		assert(scanf("%d",&confidence[i])==1);
	
	// Host and Protocol
	for(i=1;i<n;i++)
		assert(scanf("%d %d",&host[i],&protocol[i])==2);
	
	// Answer
	printf("%d\n",findSample(n,confidence,host,protocol));
	return 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...