제출 #587064

#제출 시각아이디문제언어결과실행 시간메모리
587064Jomnoi친구 (IOI14_friend)C++17
27 / 100
39 ms65536 KiB
#include <bits/stdc++.h> #include "friend.h" using namespace std; const int MAX_N = 1e5 + 5; int N, C[MAX_N]; int dp[MAX_N][2]; vector <int> graph[MAX_N]; bool visited[15][15]; void dfs(int u) { dp[u][1] = C[u]; for(auto v : graph[u]) { dfs(v); dp[u][0] += max(dp[v][0], dp[v][1]); } for(auto v : graph[u]) { dp[u][1] = max(dp[u][1], dp[u][0] - max(dp[v][0], dp[v][1]) + dp[v][0] + C[u]); } } // Find out best sample int findSample(int n, int confidence[], int host[], int protocol[]){ N = n; int cnt[3] = {}; for(int i = 0; i < N; i++) { C[i] = confidence[i]; } for(int i = 1; i < N; i++) { cnt[protocol[i]]++; } int ans = 0; if(N <= 10) { for(int i = 1; i < N; i++) { if(protocol[i] == 0) { visited[i][host[i]] = visited[host[i]][i] = true; } else if(protocol[i] == 1) { for(int j = 0; j < N; j++) { if(visited[j][host[i]] == true) { visited[i][j] = visited[j][i] = true; } } } else if(protocol[i] == 2) { for(int j = 0; j < N; j++) { if(visited[j][host[i]] == true) { visited[i][j] = visited[j][i] = true; } } visited[i][host[i]] = visited[host[i]][i] = true; } } 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 += C[i]; for(int j = 0; j < N; j++) { if((mask & (1<<j)) and visited[i][j] == true) { ok = false; } } } } if(ok == true) { ans = max(ans, sum); } } } else if(cnt[0] == N - 1) { for(int i = 1; i < N; i++) { graph[host[i]].push_back(i); graph[i].push_back(host[i]); } dfs(0); ans = max(dp[0][0], dp[0][1]); } else if(cnt[1] == N - 1) { for(int i = 0; i < N; i++) { ans += confidence[i]; } } else if(cnt[2] == N - 1) { for(int i = 0; i < N; i++) { ans = max(ans, confidence[i]); } } else { // do something } 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...