Submission #298093

#TimeUsernameProblemLanguageResultExecution timeMemory
298093mieszko11bFriend (IOI14_friend)C++14
46 / 100
35 ms1528 KiB
#include "friend.h" #include <bits/stdc++.h> using namespace std; bool subtask[6]; int G[20][20]; void add_edge(int a, int b) { G[a][b] = 1; G[b][a] = 1; //~ cout << a << " " << b << endl; } vector<int> c; int dp[1007][2]; vector<int> ch[1007]; void dfs(int w) { dp[w][1] = c[w]; for(int u : ch[w]) { dfs(u); dp[w][0] += max(dp[u][0], dp[u][1]); dp[w][1] += dp[u][0]; } } int findSample(int n,int confidence[],int host[],int protocol[]) { for(int i = 1 ; i<= 5 ; i++) subtask[i] = 1; if(n > 10) subtask[1] = 0; for(int i = 1 ; i < n ; i++) { if(protocol[i] == 0) subtask[2] = subtask[3] = 0; if(protocol[i] == 1) subtask[3] = subtask[4] = 0; if(protocol[i] == 2) subtask[2] = subtask[4] = subtask[5] = 0; } if(subtask[1]) { for(int i = 1 ; i < n ; i++) { if(protocol[i] == 0) { add_edge(i, host[i]); } else if(protocol[i] == 1) { for(int x = 0 ; x < n ; x++) if(G[host[i]][x]) add_edge(x, i); } else { for(int x = 0 ; x < n ; x++) if(G[host[i]][x]) add_edge(x, i); add_edge(i, host[i]); } } int res = 0; for(int mask = 0 ; mask < (1 << n) ; mask++) { int sum = 0; bool ok = true; for(int i = 0 ; i < n ; i++) { if(mask & (1 << i)) { sum += confidence[i]; for(int j = i + 1 ; j < n ; j++) { if(mask & (1 << j)) { if(G[i][j]) ok = false; } } } } if(ok) res = max(res, sum); } return res; } if(subtask[2]) { int sum = 0; for(int i = 0 ; i < n ; i++) sum += confidence[i]; return sum; } if(subtask[3]) { int maxv = 0; for(int i = 0 ; i < n ; i++) maxv = max(maxv, confidence[i]); return maxv; } if(subtask[4]) { c.resize(n); for(int i = 0 ; i < n ; i++) c[i] = confidence[i]; for(int i = 1 ; i < n ; i++) ch[host[i]].push_back(i); dfs(0); return max(dp[0][0], dp[0][1]); } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...