Submission #50816

#TimeUsernameProblemLanguageResultExecution timeMemory
50816Just_Solve_The_ProblemFriend (IOI14_friend)C++11
46 / 100
49 ms4688 KiB
#include <bits/stdc++.h> #include "friend.h" using namespace std; #define pb push_back #define sz(s) (int)s.size() #define pii pair < int, int > #define fr first #define sc second #define mk make_pair #define all(s) s.begin(), s.end() const int N = (int)1e5 + 7; const int smN = (int)1e3 + 7; vector < int > gr[smN]; int c[smN], dp[smN]; void addedge(int a, int b) { gr[a].pb(b); gr[b].pb(a); } void dfs(int v, int pr) { int res = 0; int res1 = 0; for (int to : gr[v]) { if (to == pr) continue; dfs(to, v); for (int tto : gr[to]) { if (tto == v) continue; res += dp[tto]; } res1 += dp[to]; } dp[v] = max(dp[v], res1); dp[v] = max(dp[v], res + c[v]); } int findSample(int n, int confidence[], int host[], int protocol[]){ for (int i = 0; i < n; i++) c[i] = confidence[i]; vector < int > vec; int ans = 0; for (int i = 1; i < n; i++) { vec.pb(protocol[i]); } sort(all(vec)); if (vec[0] == 2 && vec.back() == 2) { for (int i = 0; i < n; i++) { ans = max(ans, c[i]); } } else if (vec[0] == 1 && vec.back() == 1) { for (int i = 0; i < n; i++) { ans += c[i]; } } else if (vec[0] == 0 && vec.back() == 0) { for (int i = 1; i < n; i++) { if (protocol[i] == 0 || protocol[i] == 2) { addedge(host[i], i); } if (protocol[i] == 1 || protocol[i] == 2) { for (int to : gr[host[i]]) { addedge(to, i); } } } int st = -1; for (int i = 0; i < n; i++) { if (sz(gr[i]) == 1 && st == -1) st = i; } assert(st != -1); for (int i = 0; i < n; i++) { memset(dp, 0, sizeof dp); dfs(i, i); ans = max(ans, dp[i]); } } else { for (int i = 1; i < n; i++) { if (protocol[i] == 0 || protocol[i] == 2) { addedge(host[i], i); } if (protocol[i] == 1 || protocol[i] == 2) { for (int to : gr[host[i]]) { addedge(to, i); } } } int has[smN][smN]; memset(has, 0, sizeof has); for (int i = 0; i < n; i++) { for (int to : gr[i]) { has[i][to] = 1; } } for (int mask = 0; mask < (1 << n); mask++) { vector < int > v; for (int i = 0; i < n; i++) { if (mask & (1 << i)) { v.pb(i); } } int res = 0; bool ok = 1; for (int i = 0; i < sz(v) && ok; i++) { for (int j = i + 1; j < sz(v) && ok; j++) { if (has[v[i]][v[j]]) { ok = 0; } } } if (ok) { for (int to : v) { res += confidence[to]; } } ans = max(ans, res); } } return ans; }
#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...