# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
50519 | mirbek01 | Friend (IOI14_friend) | C++17 | 3 ms | 848 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "friend.h"
#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 2;
int n, g[N][N], dp[N], ar[N], b[N];
vector <int> G[N];
void dfs(int v, int pr){
int ch = 0;
for(int to : G[v]){
if(to == pr) continue;
dfs(to, v);
ch += dp[to];
if(pr != -1)
b[pr] += dp[to];
}
dp[v] = max(b[v] + ar[v], ch);
}
// Find out best sample
int findSample(int N,int confidence[],int host[],int protocol[]){
n = N;
int ans = 0;
if(n <= 1){
for(int i = 1; i < n; i ++){
if(protocol[i]){
for(int j = 0; j < n; j ++){
if(g[host[i]][j])
g[j][i] = g[i][j] = 1;
}
}
if(protocol[i] != 1){
g[i][host[i]] = g[host[i]][i] = 1;
}
}
for(int mask = 0; mask < (1 << n); mask ++){
vector <int> v;
int sum = 0;
for(int i = 0; i < n; i ++){
int bit = (1 << i) & mask;
if(bit){
sum += confidence[i];
v.push_back(i);
}
}
bool fl = 1;
for(int i = 0; i < v.size(); i ++){
for(int j = i + 1; j < v.size(); j ++){
if(g[v[i]][v[j]]){
fl = 0;
}
}
}
if(fl) ans = max(ans, sum);
}
} else {
if(protocol[n - 1] == 2){
for(int i = 0; i < n; i ++)
ans = max(ans, confidence[i]);
} else if(protocol[n - 1]){
for(int i = 0; i < n; i ++){
ans += confidence[i];
}
} else {
for(int i = 1; i < n; i ++){
G[host[i]].push_back(i);
G[i].push_back(host[i]);
}
for(int i = 0; i < n; i ++)
ar[i] = confidence[i];
dfs(0, -1);
ans = dp[0];
}
}
return ans;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |