제출 #478279

#제출 시각아이디문제언어결과실행 시간메모리
478279Valaki2친구 (IOI14_friend)C++14
46 / 100
27 ms3784 KiB
#include "friend.h" #include <bits/stdc++.h> using namespace std; const int IAmYourFriend = 0; const int MyFriendsAreYourFriends = 1; const int WeAreYourFriends = 2; int solve1(int n, vector<int> values, vector<int> host, vector<int> type) { vector<vector<int> > graph(1 + n); for(int i = 1; i <= n; i++) { if(type[i] == IAmYourFriend) { graph[i].push_back(host[i]); graph[host[i]].push_back(i); } if(type[i] == MyFriendsAreYourFriends) { for(int nei : graph[host[i]]) { graph[i].push_back(nei); graph[nei].push_back(i); } } if(type[i] == WeAreYourFriends) { for(int nei : graph[host[i]]) { graph[i].push_back(nei); graph[nei].push_back(i); } graph[i].push_back(host[i]); graph[host[i]].push_back(i); } } int result = 0; for(int mask = 0; mask < (1 << (1 + n)); mask++) { int cur_result = 0; vector<bool> selected(1 + n, false); for(int i = 0; i <= n; i++) { if(mask & (1 << i)) { selected[i] = true; cur_result += values[i]; } } bool ok = true; for(int i = 0; i <= n; i++) { if(selected[i]) { for(int nei : graph[i]) { if(selected[nei]) { ok = false; } } } } if(ok) { result = max(result, cur_result); } } return result; } int solve2(int n, vector<int> values, vector<int> host, vector<int> type) { int result = 0; for(int cur : values) { result += cur; } return result; } int solve3(int n, vector<int> values, vector<int> host, vector<int> type) { int result = 0; for(int cur : values) { result = max(result, cur); } return result; } vector<vector<int> > graph; vector<int> parent; vector<int> dp_chosen; vector<int> dp_not_chosen; void dfs(int cur, vector<int> &values) { for(int nei : graph[cur]) { dfs(nei, values); dp_chosen[cur] += dp_not_chosen[nei]; dp_not_chosen[cur] += max(dp_chosen[nei], dp_not_chosen[nei]); } dp_chosen[cur] += values[cur]; } int solve4(int n, vector<int> values, vector<int> host, vector<int> type) { graph.resize(1 + n); parent.assign(1 + n, 0); dp_chosen.assign(1 + n, 0); dp_not_chosen.assign(1 + n, 0); for(int i = 1; i <= n; i++) { graph[host[i]].push_back(i); parent[i] = host[i]; } dfs(0, values); return max(dp_chosen[0], dp_not_chosen[0]); } int findSample(int n,int confidence[],int host[],int protocol[]){ int _n = n - 1; vector<int> _values(1 + _n, 0); vector<int> _host(1 + _n, 0); vector<int> _type(1 + _n, 0); _values[0] = confidence[0]; vector<int> cnt(3, 0); for(int i = 1; i <= _n; i++) { _values[i] = confidence[i]; _host[i] = host[i]; _type[i] = protocol[i]; cnt[_type[i]]++; } if(n <= 10) { return solve1(_n, _values, _host, _type); } else if(cnt[MyFriendsAreYourFriends] == _n) { return solve2(_n, _values, _host, _type); } else if(cnt[WeAreYourFriends] == _n) { return solve3(_n, _values, _host, _type); } else if(cnt[IAmYourFriend] == _n) { return solve4(_n, _values, _host, _type); } return -1; }
#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...