답안 #922021

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
922021 2024-02-04T18:24:55 Z Macker 친구 (IOI14_friend) C++14
46 / 100
135 ms 65536 KB
#include "friend.h"
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
#define all(v) v.begin(), v.end()
// Find out best sample
int findSample(int n,int confidence[],int host[],int protocol[]){
	bool no0 = 1, no1 = 1, no2 = 1;
	for (int i = 1; i < n; i++) {
		if(protocol[i] == 0) no0 = false;
		if(protocol[i] == 1) no1 = false;
		if(protocol[i] == 2) no2 = false;
	}

	vector<vector<int>> adj(n);
	for (int i = 1; i < n; i++) {
		if(protocol[i] == 1 || protocol[i] == 2){
			for (auto &j : adj[host[i]]) {
				adj[i].push_back(j);
				adj[j].push_back(i);
			}
		}
		if(protocol[i] == 0 || protocol[i] == 2) {
			adj[i].push_back(host[i]);
			adj[host[i]].push_back(i);
		}
	}
	

	if(no0 && no2){ // no edges
		int res = 0;
		for (int i = 0; i < n; i++) {
			res += confidence[i];
		}
		return res;
	}
	if(no0 && no1){ // fully conected
		int res = 0;
		for (int i = 0; i < n; i++) {
			res = max(res, confidence[i]);
		}
		return res;
	}
	if(no1 && no2){ // tree
		vector<int> odp(n, 0);
		vector<int> ndp(n, 0);

		function<void(int, int)> dfs = [&](int a, int p){
			odp[a] = confidence[a];
			for (auto &b : adj[a]) {
				if(b == p) continue;
				dfs(b, a);
				ndp[a] += max(odp[b], ndp[b]);
				odp[a] += ndp[b];
			}
		};
		dfs(0, 0);
		return max(odp[0], ndp[0]);
	}
	if(n <= 15){ // brute force
		int mx = 0;
		for (int i = 0; i < (1 << n); i++) {
			vector<bool> active(n, 0);
			int res = 0;
			bool bad = 0;
			for (int j = 0; j < n; j++) {
				if(i & (1 << j)){
					active[j] = 1;
					res += confidence[j];
				}
			}
			for (int j = 0; j < n; j++) {
				for (auto &k : adj[j]) {
					if(active[j] && active[k]) bad = 1;
				}
			}
			if(!bad) mx = max(mx, res);
		}
		return mx;
	}
	return -1;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 600 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1112 KB Output is correct
2 Correct 4 ms 4188 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 3 ms 3164 KB Output is correct
5 Correct 4 ms 4188 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 860 KB Output is correct
8 Correct 1 ms 1116 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 4 ms 4444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 452 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Incorrect 0 ms 348 KB Output isn't correct
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Runtime error 135 ms 65536 KB Execution killed with signal 9
13 Halted 0 ms 0 KB -