Submission #874044

# Submission time Handle Problem Language Result Execution time Memory
874044 2023-11-16T08:21:23 Z hmm789 Friend (IOI14_friend) C++14
35 / 100
1 ms 604 KB
#include <bits/stdc++.h>
#include "friend.h"
using namespace std;

int memo[1000][2], c[1000];
vector<int> adj[1000];
int dp(int x, int f, int p) {
	if(memo[x][f] != -1) return memo[x][f];
	int ans = (f==1?c[x]:0);
	for(int i : adj[x]) if(i != p) {
		if(f == 1) ans += dp(i, 0, x);
		else ans += max(dp(i, 0, x), dp(i, 1, x));
	}
	return memo[x][f] = ans;
}

int findSample(int n, int confidence[], int host[], int protocol[]) {
	bool st2 = true, st3 = true, st4 = true, st5 = true;
	for(int i = 0; i < n; i++) c[i] = confidence[i];
	for(int i = 1; i < n; i++) {
		if(protocol[i] != 0) st4 = false;
		if(protocol[i] != 1) st2 = false;
		if(protocol[i] != 2) st3 = false;
		if(protocol[i] == 2) st5 = false;
	}
	if(st2) {
		int sm = 0;
		for(int i = 0; i < n; i++) sm += confidence[i];
		return sm;
	} else if(st3) {
		int mx = 0;
		for(int i = 0; i < n; i++) mx = max(mx, confidence[i]);
		return mx;
	}
	for(int i = 1; i < n; i++) {
		if(protocol[i] != 0) {
			for(int x : adj[host[i]]) {
				adj[x].push_back(i);
				adj[i].push_back(x);
			}
		} else if(protocol[i] != 1) {
			adj[i].push_back(host[i]);
			adj[host[i]].push_back(i);
		}
	}
	if(n <= 10) {
		int am[n][n], ans = 0;
		memset(am, 0, sizeof(am));
		for(int i = 0; i < n; i++) {
			for(int j : adj[i]) am[i][j] = 1;
		}
		for(int i = 0; i < 1<<n; i++) {
			vector<int> v;
			for(int j = 0; j < n; j++) {
				if(i&(1<<j)) v.push_back(j);
			}
			int sm = 0;
			for(int j = 0; j < v.size(); j++) {
				for(int k = j+1; k < v.size(); k++) {
					if(k >= v.size()) break;
					if(am[v[j]][v[k]]) goto ed;
				}
			}
			for(int j = 0; j < v.size(); j++) sm += c[v[j]];
			ans = max(ans, sm);
			ed:;
		}
		return ans;
	} else if(st4) {
		memset(memo, -1, sizeof(memo));
		return max(dp(0, 0, -1), dp(0, 1, -1));
	} else if(st5) {
		int ans[2], dist[n];
		ans[0] = ans[1] = 0;
		memset(dist, -1, sizeof(dist));
		dist[0] = 0;
		ans[0] += c[0];
		queue<int> q;
		q.push(0);
		while(!q.empty()) {
			int cur = q.front();
			q.pop();
			for(int i : adj[cur]) {
				if(dist[i] != -1) continue;
				dist[i] = dist[cur]^1;
				ans[dist[i]] += c[i];
				q.push(i);
			}
		}
		return max(ans[0], ans[1]);
	}
	return 0;
}

Compilation message

friend.cpp: In function 'int findSample(int, int*, int*, int*)':
friend.cpp:58:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   58 |    for(int j = 0; j < v.size(); j++) {
      |                   ~~^~~~~~~~~~
friend.cpp:59:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |     for(int k = j+1; k < v.size(); k++) {
      |                      ~~^~~~~~~~~~
friend.cpp:60:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   60 |      if(k >= v.size()) break;
      |         ~~^~~~~~~~~~~
friend.cpp:64:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   64 |    for(int j = 0; j < v.size(); j++) sm += c[v[j]];
      |                   ~~^~~~~~~~~~
# Verdict Execution time Memory 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 Incorrect 0 ms 348 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory 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 0 ms 348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 484 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 0 ms 348 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory 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 1 ms 604 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 0 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 348 KB Output is correct
# Verdict Execution time Memory 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 1 ms 348 KB Output is correct
6 Correct 0 ms 348 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 604 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Incorrect 0 ms 348 KB Output isn't correct
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 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 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Incorrect 1 ms 344 KB Output isn't correct
12 Halted 0 ms 0 KB -