제출 #1327247

#제출 시각아이디문제언어결과실행 시간메모리
1327247orgiloogii친구 (IOI14_friend)C++20
컴파일 에러
0 ms0 KiB
//#include "friend.h"
#include <bits/stdc++.h>
using namespace std;

int sub1 (int n, int confidence[], int host[], int protocol[]) {
	bool friends[n][n];
	for (int i = 0;i < n;i++) {
		for (int j = 0;j < n;j++) {
			friends[i][j] = 0;
		}
	}
	for (int i = 1;i < n;i++) {
		if (protocol[i] == 0) {
			friends[host[i]][i] = true;
			friends[i][host[i]] = true;
		}
		if (protocol[i] == 1) {
			for (int j = 0;j <= n;j++) {
				if (friends[host[i]][j] == true) {
					friends[j][i] = true;
					friends[i][j] = true;
				}
			}
		}
		if (protocol[i] == 2) {
			friends[host[i]][i] = true;
			friends[i][host[i]] = true;
			for (int j = 0;j <= n;j++) {
				if (friends[host[i]][j] == true) {
					friends[j][i] = true;
					friends[i][j] = true;
				}
			}
		}
	} 
	// for (int i = 0;i < n;i++) {
	// 	for (int j = 0;j < n;j++) {
	// 		cout << friends[i][j];
	// 	}
	// 	cout << endl;
	// }
	//check
	int k = (1 << n);
	int ans = 0;
	for (int i = 0;i < k;i++) {
		int res = 0;
		vector <int> v;
		for (int j = 0;j < n;j++) {
			if (((1 << j) & i)) {
				v.push_back(j);
				res += confidence[j];
			}
		}
		bool pos = true;
		for (int j = 0;j < v.size();j++) {
			for (int l = j + 1;l < v.size();l++) {
				if (friends[v[j]][v[l]] == true) {
					pos = false;
					break;
				}
			}
		}
		if (pos) {
			ans = max(ans, res);
		}
	}
	return ans;
}

int sub2 (int n, int confidence[], int host[], int protocol[]) {
	int ans = 0;
	for (int i = 0;i < n;i++) {
		ans += confidence[i];
	}
	return ans;
}

int sub3 (int n, int confidence[], int host[], int protocol[]) {
	int ans = 0;
	for (int i = 0;i < n;i++) {
		ans = max(ans, confidence[i]);
	}
	return ans;
}

int sub4 (int n, int confidence[], int host[], int protocol[]) {

}

int findSample(int n, int confidence[], int host[], int protocol[]){
	int ans = 10;
	int prot = -1;
	for (int i = 0;i < n;i++) {
		if (prot == -1) {
			prot = protocol[i];
		}
		if (prot != protocol[i]) {
			prot = -2;
		}
	}
	if (n <= 10) {
		return sub1(n, confidence, host, protocol);
	}
	if (prot == 0) {
		return sub2(n, confidence, host, protocol);
	}
	if (prot == 1) {
		return sub3(n, confidence, host, protocol);
	}
	if (prot == 2) {
		return sub4(n, confidence, host, protocol);
	}
	if (prot == -2) return 0;
	return ans;
}

signed main() {
	int n;
	cin >> n;
	int confidence[n];
	for (int i = 0;i < n;i++) {
		cin >> confidence[i];
	}
	int host[n], protocol[n];
	for (int i = 1;i < n;i++) {
		cin >> host[i] >> protocol[i];
	}
	cout << findSample(n, confidence, host, protocol);
}

컴파일 시 표준 에러 (stderr) 메시지

friend.cpp: In function 'int sub4(int, int*, int*, int*)':
friend.cpp:88:1: warning: no return statement in function returning non-void [-Wreturn-type]
   88 | }
      | ^
/usr/bin/ld: /tmp/cccAS243.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/cc4yK8wG.o:friend.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status