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;
bool subtask[6];
int G[20][20];
void add_edge(int a, int b) {
G[a][b] = 1;
G[b][a] = 1;
//~ cout << a << " " << b << endl;
}
int findSample(int n,int confidence[],int host[],int protocol[]) {
for(int i = 1 ; i<= 5 ; i++)
subtask[i] = 1;
if(n > 10)
subtask[1] = 0;
for(int i = 1 ; i < n ; i++) {
if(protocol[i] == 0)
subtask[2] = subtask[3] = 0;
if(protocol[i] == 1)
subtask[3] = subtask[4] = 0;
if(protocol[i] == 2)
subtask[2] = subtask[4] = subtask[5] = 0;
}
if(subtask[1]) {
for(int i = 1 ; i < n ; i++) {
if(protocol[i] == 0) {
add_edge(i, host[i]);
} else if(protocol[i] == 1) {
for(int x = 0 ; x < n ; x++)
if(G[host[i]][x])
add_edge(x, i);
} else {
for(int x = 0 ; x < n ; x++)
if(G[host[i]][x])
add_edge(x, i);
add_edge(i, host[i]);
}
}
int res = 0;
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 += confidence[i];
for(int j = i + 1 ; j < n ; j++) {
if(mask & (1 << j)) {
if(G[i][j])
ok = false;
}
}
}
}
if(ok)
res = max(res, sum);
}
return res;
}
if(subtask[2]) {
int sum = 0;
for(int i = 0 ; i < n ; i++)
sum += confidence[i];
return sum;
}
if(subtask[3]) {
int maxv = 0;
for(int i = 0 ; i < n ; i++)
maxv = max(maxv, confidence[i]);
return maxv;
}
return 0;
}
# | 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... |