Submission #285619

#TimeUsernameProblemLanguageResultExecution timeMemory
2856192qbingxuanFriend (IOI14_friend)C++14
46 / 100
33 ms1536 KiB
#include "friend.h" #include <bits/stdc++.h> #ifdef local #define debug(...) qqbx(#__VA_ARGS__, __VA_ARGS__) void qqbx(const char *s) {} template <typename H, typename ...T> void qqbx(const char *s, const H& h, T&& ...args) { for(; *s && *s != ','; ++s) if(*s != ' ') std::cerr << *s; std::cerr << " = " << h << (sizeof...(T) ? ", " : "\n"); if(sizeof...(T)) qqbx(++s, args...); } #define safe std::cerr<<__PRETTY_FUNCTION__<<" line "<<__LINE__<<" safe\n" #else #define debug(...) ((void)0) #define safe ((void)0) #endif // local #define pb emplace_back #define all(v) begin(v),end(v) using namespace std; int findSample(int n, int confidence[], int host[], int protocol[]){ int ans = 0; auto isNothing = [&]() -> bool { for(int i = 1; i < n; i++) if(protocol[i] != 1) return false; return true; }; auto isComplete = [&]() -> bool { for(int i = 1; i < n; i++) if(protocol[i] != 2) return false; return true; }; auto isTree = [&]() -> bool { for(int i = 1; i < n; i++) if(protocol[i] != 0) return false; return true; }; if(isComplete()) { return *max_element(confidence, confidence+n); } if(isTree()) { vector<vector<int>> g(n); vector<array<int,2>> dp(n); for(int i = 1; i < n; i++) g[host[i]].pb(i); function<void(int,int)> dfs = [&](int i, int p) { dp[i][0] = 0, dp[i][1] = confidence[i]; for(int j: g[i]) { if(j == p) continue; dfs(j, i); dp[i][0] += max(dp[j][0], dp[j][1]); dp[i][1] += dp[j][0]; } }; dfs(0, -1); return max(dp[0][0], dp[0][1]); } if(isNothing()) { long long sum = 0; for(int i = 0; i < n; i++) sum += confidence[i]; return sum; } if(n <= 20) { int g[10] = {}; for(int i = 1; i < n; i++) { if(protocol[i] == 0) { g[i] |= 1 << host[i]; g[host[i]] |= 1 << i; } else if(protocol[i] == 1) { g[i] |= g[host[i]]; for(int j = 0; j < n; j++) if(g[host[i]] >> j & 1) g[j] |= 1 << i; } else if(protocol[i] == 2) { g[i] |= g[host[i]]; for(int j = 0; j < n; j++) if(g[host[i]] >> j & 1) g[j] |= 1 << i; g[i] |= 1 << host[i]; g[host[i]] |= 1 << i; } } int ans = 0; /* vector<int> wei(1<<n); */ /* for(int i = 0; i < n; i++) wei[1<<i] = confidence[i]; */ /* for(int s = 0; s < (1<<n); s++) wei[s] += wei[s - (s&-s)]; */ for(int s = 0; s < (1<<n); s++) { bool ok = 1; for(int i = 0; i < n; i++) if((s >> i & 1) && (g[i] & s)) ok = 0; if(ok) { int sum = 0; for(int i = 0; i < n; i++) if(s >> i & 1) sum += confidence[i]; ans = max(ans, sum); } } return ans; } return -1; }

Compilation message (stderr)

friend.cpp: In function 'int findSample(int, int*, int*, int*)':
friend.cpp:21:9: warning: unused variable 'ans' [-Wunused-variable]
   21 |     int ans = 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...