제출 #874116

#제출 시각아이디문제언어결과실행 시간메모리
874116siewjh친구 (IOI14_friend)C++17
35 / 100
1 ms4696 KiB
#include "friend.h" #include <bits/stdc++.h> using namespace std; const int MAXN = 100005; vector<int> adj[MAXN]; int dp[MAXN][2], conf[MAXN]; int dfs(int x, bool take){ if (dp[x][take] != -1) return dp[x][take]; int ans = 0; if (take){ ans = conf[x]; for (int nxt : adj[x]) ans += dfs(nxt, 0); } else{ for (int nxt : adj[x]) ans += max(dfs(nxt, 1), dfs(nxt, 0)); } return dp[x][take] = ans; } // Find out best sample int findSample(int n, int confidence[], int host[], int protocol[]){ if (protocol[1] == 0){ for (int i = 1; i < n; i++) adj[host[i]].push_back(i); for (int i = 0; i < n; i++) conf[i] = confidence[i]; memset(dp, -1, sizeof(dp)); return max(dfs(0, 0), dfs(0, 1)); } else if (protocol[1] == 1){ int ans = 0; for (int i = 0; i < n; i++) ans += confidence[i]; return ans; } else{ int ans = 0; for (int i = 0; i < n; i++) ans = max(ans, confidence[i]); 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...