Submission #607491

#TimeUsernameProblemLanguageResultExecution timeMemory
607491skittles1412Friend (IOI14_friend)C++17
46 / 100
145 ms65536 KiB
#include "bits/extc++.h" using namespace std; template <typename T> void dbgh(const T& t) { cerr << t << endl; } template <typename T, typename... U> void dbgh(const T& t, const U&... u) { cerr << t << " | "; dbgh(u...); } #ifdef DEBUG #define dbg(...) \ cerr << "L" << __LINE__ << " [" << #__VA_ARGS__ << "]: "; \ dbgh(__VA_ARGS__); #else #define dbg(...) #define cerr \ if (false) \ cerr #endif #define endl "\n" #define long int64_t #define sz(x) int((x).size()) const int maxn = 1e5 + 5; int arr[maxn], memo[maxn][2]; vector<int> graph[maxn]; void pdfs(int u) { for (auto& v : graph[u]) { graph[v].erase(find(begin(graph[v]), end(graph[v]), u)); pdfs(v); } } int dp(int u, bool cur) { int& ans = memo[u][cur]; if (ans != -1) { return ans; } ans = cur * arr[u]; for (auto& v : graph[u]) { if (cur) { ans += dp(v, false); } else { ans += max(dp(v, false), dp(v, true)); } } return ans; } int findSample(int n, int _arr[], int host[], int protocol[]) { copy(_arr, _arr + n, arr); for (int i = 1; i < n; i++) { if (protocol[i] == 0 || protocol[i] == 2) { graph[i].push_back(host[i]); } if (protocol[i] == 1 || protocol[i] == 2) { graph[i].insert(graph[i].end(), begin(graph[host[i]]), end(graph[host[i]])); } for (auto& a : graph[i]) { graph[a].push_back(i); } } if (n <= 10) { int ans = 0; for (int i = 0; i < (1 << n); i++) { int cans = 0; for (int j = 0; j < n; j++) { if ((i >> j) & 1) { cans += arr[j]; for (auto& a : graph[j]) { if ((i >> a) & 1) { goto loop; } } } } ans = max(ans, cans); loop:; } return ans; } if (protocol[1] == 1) { for (auto& a : graph) { assert(!sz(a)); } return accumulate(arr, arr + n, 0); } else if (protocol[1] == 2) { return *max_element(arr, arr + n); } pdfs(0); memset(memo, -1, sizeof(memo)); return max(dp(0, false), dp(0, true)); }
#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...