# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
114384 | 2019-06-01T07:08:32 Z | E869120 | Friend (IOI14_friend) | C++14 | 33 ms | 5212 KB |
#include "friend.h" #include <bits/stdc++.h> using namespace std; vector<int> G[100009]; int dp[100009][2], A[100009]; void dfs(int pos) { int m1 = 0, m2 = 0; for (int i = 0; i < G[pos].size(); i++) { dfs(G[pos][i]); m1 += max(dp[G[pos][i]][0], dp[G[pos][i]][1]); m2 += dp[G[pos][i]][1]; } m2 += A[pos]; dp[pos][0] = m2; dp[pos][1] = m1; } // Find out best sample int findSample(int n,int confidence[],int host[],int protocol[]){ int bit = 0; for (int i = 1; i <= n - 1; i++) bit |= (1 << protocol[i]); if (bit == 1) { // Subtask 4. for (int i = 0; i < n; i++) A[i] = confidence[i]; for (int i = 1; i <= n - 1; i++) G[host[i]].push_back(i); dfs(0); return max(dp[0][0], dp[0][1]); } if (bit == 2) { // Subtask 2. int sum = 0; for (int i = 0; i < n; i++) sum += confidence[i]; return sum; } if (bit == 4) { // Subtask 3. int sum = 0; for (int i = 0; i < n; i++) sum = max(sum, confidence[i]); return sum; } if (n <= 10) { // Subtask 1. for (int i = 1; i <= n - 1; i++) { if (protocol[i] == 0 || protocol[i] == 2) { G[host[i]].push_back(i); G[i].push_back(host[i]); } if (protocol[i] == 1 || protocol[i] == 2) { for (int pos : G[host[i]]) { if (pos == i) continue; G[pos].push_back(i); G[i].push_back(pos); } } } int ans = 0; for (int i = 0; i < (1 << n); i++) { bool flag = false; int sum = 0; int bit[10]; for (int j = 0; j < n; j++) { bit[j] = (i / (1 << j)) % 2; sum += bit[j] * confidence[j]; } for (int j = 0; j < n; j++) { for (int k = 0; k < G[j].size(); k++) { if (bit[j] == 1 && bit[G[j][k]] == 1) flag = true; } } if (flag == false) ans = max(ans, sum); } return ans; } return -1; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 2688 KB | Output is correct |
2 | Correct | 4 ms | 2688 KB | Output is correct |
3 | Correct | 4 ms | 2688 KB | Output is correct |
4 | Correct | 4 ms | 2688 KB | Output is correct |
5 | Correct | 4 ms | 2688 KB | Output is correct |
6 | Correct | 4 ms | 2688 KB | Output is correct |
7 | Correct | 4 ms | 2688 KB | Output is correct |
8 | Correct | 4 ms | 2688 KB | Output is correct |
9 | Correct | 4 ms | 2688 KB | Output is correct |
10 | Correct | 4 ms | 2688 KB | Output is correct |
11 | Correct | 4 ms | 2688 KB | Output is correct |
12 | Correct | 4 ms | 2688 KB | Output is correct |
13 | Correct | 4 ms | 2688 KB | Output is correct |
14 | Correct | 3 ms | 2688 KB | Output is correct |
15 | Correct | 4 ms | 2688 KB | Output is correct |
16 | Correct | 4 ms | 2688 KB | Output is correct |
17 | Correct | 3 ms | 2688 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 2688 KB | Output is correct |
2 | Correct | 4 ms | 2688 KB | Output is correct |
3 | Correct | 4 ms | 2688 KB | Output is correct |
4 | Correct | 4 ms | 2688 KB | Output is correct |
5 | Correct | 4 ms | 2688 KB | Output is correct |
6 | Correct | 4 ms | 2688 KB | Output is correct |
7 | Correct | 4 ms | 2688 KB | Output is correct |
8 | Correct | 4 ms | 2688 KB | Output is correct |
9 | Correct | 4 ms | 2688 KB | Output is correct |
10 | Correct | 4 ms | 2688 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 2688 KB | Output is correct |
2 | Correct | 4 ms | 2688 KB | Output is correct |
3 | Correct | 4 ms | 2688 KB | Output is correct |
4 | Correct | 4 ms | 2688 KB | Output is correct |
5 | Correct | 4 ms | 2688 KB | Output is correct |
6 | Correct | 4 ms | 2688 KB | Output is correct |
7 | Correct | 4 ms | 2688 KB | Output is correct |
8 | Correct | 4 ms | 2688 KB | Output is correct |
9 | Correct | 4 ms | 2688 KB | Output is correct |
10 | Correct | 4 ms | 2688 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 2688 KB | Output is correct |
2 | Correct | 4 ms | 2688 KB | Output is correct |
3 | Correct | 4 ms | 2688 KB | Output is correct |
4 | Correct | 3 ms | 2688 KB | Output is correct |
5 | Correct | 7 ms | 2816 KB | Output is correct |
6 | Correct | 4 ms | 2688 KB | Output is correct |
7 | Correct | 3 ms | 2688 KB | Output is correct |
8 | Correct | 4 ms | 2816 KB | Output is correct |
9 | Correct | 4 ms | 2688 KB | Output is correct |
10 | Correct | 4 ms | 2688 KB | Output is correct |
11 | Correct | 4 ms | 2688 KB | Output is correct |
12 | Correct | 5 ms | 2816 KB | Output is correct |
13 | Correct | 4 ms | 2688 KB | Output is correct |
14 | Correct | 4 ms | 2688 KB | Output is correct |
15 | Correct | 4 ms | 2816 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 2688 KB | Output is correct |
2 | Correct | 4 ms | 2688 KB | Output is correct |
3 | Correct | 4 ms | 2688 KB | Output is correct |
4 | Correct | 4 ms | 2688 KB | Output is correct |
5 | Correct | 4 ms | 2688 KB | Output is correct |
6 | Correct | 4 ms | 2688 KB | Output is correct |
7 | Correct | 4 ms | 2688 KB | Output is correct |
8 | Correct | 4 ms | 2688 KB | Output is correct |
9 | Correct | 4 ms | 2816 KB | Output is correct |
10 | Correct | 4 ms | 2688 KB | Output is correct |
11 | Incorrect | 4 ms | 2688 KB | Output isn't correct |
12 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 2688 KB | Output is correct |
2 | Correct | 4 ms | 2688 KB | Output is correct |
3 | Correct | 4 ms | 2688 KB | Output is correct |
4 | Correct | 4 ms | 2688 KB | Output is correct |
5 | Correct | 4 ms | 2688 KB | Output is correct |
6 | Correct | 4 ms | 2688 KB | Output is correct |
7 | Correct | 4 ms | 2816 KB | Output is correct |
8 | Correct | 3 ms | 2688 KB | Output is correct |
9 | Correct | 4 ms | 2688 KB | Output is correct |
10 | Correct | 4 ms | 2688 KB | Output is correct |
11 | Correct | 3 ms | 2688 KB | Output is correct |
12 | Incorrect | 33 ms | 5212 KB | Output isn't correct |
13 | Halted | 0 ms | 0 KB | - |