# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
69737 | E869120 | Friend (IOI14_friend) | C++14 | 42 ms | 3092 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |