제출 #586342

#제출 시각아이디문제언어결과실행 시간메모리
586342LastRoninFriend (IOI14_friend)C++14
16 / 100
1 ms212 KiB
#include "friend.h"
#include <bits/stdc++.h>
#define ll long long
using namespace std;

const ll N = 1e3 + 10;

bool can[N][N];

int findSample(int n,int confidence[],int host[],int protocol[]){
    bool eq = 1;
    for(int j = 1; j < n - 1; j++) {
		if(protocol[j] != protocol[j + 1])
			eq = 0;						
    }
    if(eq) {
    	if(protocol[1] == 1) {
			// empty
			ll sum = 0;
			for(int j = 0; j < n; j++)
				sum += confidence[j];
			return sum;
    	} else if(protocol[1] == 2) {
			// full
			ll mx = 0;
			for(int j = 0; j < n; j++)
				mx = max(mx, (ll)confidence[j]);
			return mx;
    	} else if(protocol[1] == 0) {
    		// tree
    		return -1;
    	}
    } else {
    	for(int j = 1; j < n; j++) {
			if(protocol[j] == 0) {
				can[j][host[j]] = 1;
				can[host[j]][j] = 1;
            } else if(protocol[j] == 1) {
            	for(int i = 0; i < n; i++) {
            		if(can[host[j]][i])
            			can[i][j] = can[j][i] = 1;
            	}
            } else {
            	for(int i = 0; i < n; i++) {
            		if(can[host[j]][i])
            			can[i][j] = can[j][i] = 1;
            	}
            	can[j][host[j]] = 1;
            	can[host[j]][j] = 1;
            }
    	}
    	if(n > 10)return 0;
    	ll mx = 0;
		for(int j = 0; j < (1<<n); j++) {
			bool incor = 0;			
			ll sum = 0;
			for(int i = 0; i < n; i++) {
				if((1<<i)&j)
					sum = sum + confidence[i]; 					
				for(int k = 0; k < n; k++) {
					if(((1<<i)&j) && ((1<<k)&j) && can[i][k]) {
						incor = 1;
					}
				}
			}
			if(!incor)
				mx = max(mx, sum);
		}
		return mx;
    }
	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...