Submission #701937

#TimeUsernameProblemLanguageResultExecution timeMemory
701937CyanmondFriend (IOI14_friend)C++17
11 / 100
23 ms3916 KiB
#include "friend.h"
#include <bits/stdc++.h>

int findSample(int n, int confidence[], int host[], int protocol[]){
	assert(n <= 10);
	std::vector<std::vector<bool>> isFriend(n, std::vector<bool>(n));
	for (int x = 1; x < n; ++x) {
		const int h = host[x], type = protocol[x];
		if (type == 0) {
			isFriend[h][x] = isFriend[x][h] = true;
		} else if (type == 1) {
			for (int i = 0; i < n; ++i) {
				if (isFriend[h][i]) {
					isFriend[i][x] = isFriend[x][i] = true;
				}
			}
		} else if (type == 2) {
			for (int i = 0; i < n; ++i) {
				if (isFriend[h][i]) {
					isFriend[i][x] = isFriend[x][i] = true;
				}
			}
			isFriend[h][x] = isFriend[x][h] = true;
		}
	}

	int answer = 0;
	for (int bits = 0; bits < (1 << n); ++bits) {
		bool isOk = true;
		for (int i = 0; i < n; ++i) {
			if (not(bits & (1 << i))) {
				continue;
			}
			for (int j = 0; j < n; ++j) {
				if (not(bits & (1 << j))) {
					continue;
				}
				if (isFriend[i][j]) {
					isOk = false;
				}
			}
		}
		int sum = 0;
		if (isOk) {
			for (int i = 0; i < n; ++i) {
				if (not(bits & (1 << i))) {
					continue;
				}
				sum += confidence[i];
			}
			answer = std::max(answer, sum);
		}
	}
	return answer;
}
#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...