Submission #69737

# Submission time Handle Problem Language Result Execution time Memory
69737 2018-08-21T12:24:14 Z E869120 Friend (IOI14_friend) C++14
27 / 100
42 ms 3092 KB
#include "friend.h"
#include <algorithm>
#include <vector>
#include <iostream>
using namespace std;

// Find out best sample

int p[12][12]; vector<int>x[1009];
int dp[1009][2], conf[1009];

void dfs(int pos) {
	for (int i = 0; i < x[pos].size(); i++) dfs(x[pos][i]);

	for (int i = 0; i < x[pos].size(); i++) dp[i][0] += max(dp[x[pos][i]][0], dp[x[pos][i]][1]);
	for (int i = 0; i < x[pos].size(); i++) dp[i][1] += dp[x[pos][i]][0];
}

int findSample(int n, int confidence[], int host[], int protocol[]) {
	if (n <= 10) {
		for (int i = 1; i <= n - 1; i++) {
			if (protocol[i] == 0 || protocol[i] == 2) {
				p[host[i]][i] = 1;
				p[i][host[i]] = 1;
			}
			if (protocol[i] == 1 || protocol[i] == 2) {
				for (int j = 0; j < n; j++) {
					if (p[host[i]][j] == 1) {
						p[j][i] = 1; p[i][j] = 1;
					}
				}
			}
		}
		int maxn = 0;
		for (int i = 0; i < (1 << n); i++) {
			vector<int>vec;
			for (int j = 0; j < n; j++) { if ((i / (1 << j)) % 2 == 1) vec.push_back(j); }
			bool OK = true;
			for (int j = 0; j < vec.size(); j++) {
				for (int k = j + 1; k < vec.size(); k++) {
					if (p[vec[j]][vec[k]] == 1) OK = false;
				}
			}
			if (OK == false) continue;
			int bit = 0; for (int j = 0; j < vec.size(); j++) bit += confidence[vec[j]];
			maxn = max(maxn, bit);
		}
		return maxn;
	}
	else {
		int c[3] = { 0,0,0 }; for (int i = 1; i < n; i++) c[protocol[i]] = 1;
		int bit = c[0] * 1 + c[1] * 2 + c[2] * 4;
		for (int i = 0; i < n; i++) conf[i] = confidence[i];

		if (bit == 4) {
			int maxn = 0;
			for (int i = 0; i < n; i++) maxn = max(maxn, confidence[i]);
			return maxn;
		}
		if (bit == 2) {
			int cnts = 0;
			for (int i = 0; i < n; i++) cnts += confidence[i];
			return cnts;
		}
		if (bit == 1) {
			for (int i = 1; i < n; i++) { x[host[i]].push_back(i); }
			dfs(0);
			return max(dp[0][0], dp[0][1]);
		}
	}
	return -1;
}

Compilation message

friend.cpp: In function 'void dfs(int)':
friend.cpp:13:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < x[pos].size(); i++) dfs(x[pos][i]);
                  ~~^~~~~~~~~~~~~~~
friend.cpp:15:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < x[pos].size(); i++) dp[i][0] += max(dp[x[pos][i]][0], dp[x[pos][i]][1]);
                  ~~^~~~~~~~~~~~~~~
friend.cpp:16:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < x[pos].size(); i++) dp[i][1] += dp[x[pos][i]][0];
                  ~~^~~~~~~~~~~~~~~
friend.cpp: In function 'int findSample(int, int*, int*, int*)':
friend.cpp:39:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for (int j = 0; j < vec.size(); j++) {
                    ~~^~~~~~~~~~~~
friend.cpp:40:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int k = j + 1; k < vec.size(); k++) {
                         ~~^~~~~~~~~~~~
friend.cpp:45:35: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    int bit = 0; for (int j = 0; j < vec.size(); j++) bit += confidence[vec[j]];
                                 ~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 432 KB Output is correct
3 Correct 2 ms 560 KB Output is correct
4 Correct 2 ms 560 KB Output is correct
5 Correct 2 ms 560 KB Output is correct
6 Correct 3 ms 560 KB Output is correct
7 Correct 3 ms 588 KB Output is correct
8 Correct 3 ms 668 KB Output is correct
9 Correct 3 ms 668 KB Output is correct
10 Correct 2 ms 668 KB Output is correct
11 Correct 2 ms 668 KB Output is correct
12 Correct 3 ms 696 KB Output is correct
13 Correct 3 ms 696 KB Output is correct
14 Correct 3 ms 696 KB Output is correct
15 Correct 2 ms 696 KB Output is correct
16 Correct 2 ms 696 KB Output is correct
17 Correct 3 ms 696 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 696 KB Output is correct
2 Correct 2 ms 696 KB Output is correct
3 Correct 3 ms 696 KB Output is correct
4 Correct 3 ms 696 KB Output is correct
5 Correct 3 ms 696 KB Output is correct
6 Correct 3 ms 696 KB Output is correct
7 Correct 2 ms 696 KB Output is correct
8 Correct 3 ms 696 KB Output is correct
9 Correct 4 ms 696 KB Output is correct
10 Correct 3 ms 696 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 696 KB Output is correct
2 Correct 3 ms 696 KB Output is correct
3 Correct 3 ms 696 KB Output is correct
4 Correct 3 ms 696 KB Output is correct
5 Correct 3 ms 696 KB Output is correct
6 Correct 3 ms 696 KB Output is correct
7 Correct 3 ms 696 KB Output is correct
8 Correct 2 ms 696 KB Output is correct
9 Correct 3 ms 696 KB Output is correct
10 Correct 3 ms 728 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 728 KB Output is correct
2 Correct 3 ms 728 KB Output is correct
3 Correct 3 ms 728 KB Output is correct
4 Correct 3 ms 728 KB Output is correct
5 Incorrect 2 ms 728 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 728 KB Output is correct
2 Correct 3 ms 728 KB Output is correct
3 Correct 3 ms 728 KB Output is correct
4 Correct 3 ms 728 KB Output is correct
5 Correct 3 ms 728 KB Output is correct
6 Correct 7 ms 728 KB Output is correct
7 Correct 2 ms 728 KB Output is correct
8 Correct 2 ms 728 KB Output is correct
9 Incorrect 3 ms 728 KB Output isn't correct
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 728 KB Output is correct
2 Correct 3 ms 728 KB Output is correct
3 Correct 3 ms 728 KB Output is correct
4 Correct 2 ms 728 KB Output is correct
5 Correct 3 ms 728 KB Output is correct
6 Correct 2 ms 728 KB Output is correct
7 Correct 2 ms 728 KB Output is correct
8 Correct 3 ms 728 KB Output is correct
9 Correct 2 ms 728 KB Output is correct
10 Correct 2 ms 728 KB Output is correct
11 Correct 2 ms 740 KB Output is correct
12 Runtime error 42 ms 3092 KB Execution killed with signal 11 (could be triggered by violating memory limits)
13 Halted 0 ms 0 KB -