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;
#define st first
#define nd second
#define sz(x) (x.size())
#define pb push_back
int solve_naive(int n,int confidence[],int host[],int protocol[]) {
int way[15][15]={0};
for(int i=1;i<n;i++) {
if(protocol[i]==1 || protocol[i]==2) {
for(int j=0;j<n;j++) {
if(way[host[i]][j]) {
way[i][j]=way[j][i]=1;
}
}
}
if(protocol[i]==0 || protocol[i]==2) {
way[host[i]][i]=way[i][host[i]]=1;
}
}
int ans=0;
for(int i=0;i<(1<<n);i++) {
vector<int> took;
int tot=0;
for(int j=0;j<n;j++) {
if(i&(1<<j)) {
took.pb(j);
tot+=confidence[j];
}
}
bool flag=true;
for(int j=0;j<sz(took);j++) {
for(int k=0;k<j;k++) {
if(way[took[j]][took[k]]) flag=false;
}
}
if(flag==true) ans=max(ans,tot);
}
return ans;
}
int solve_tree(int n,int confidence[],int host[],int protocol[]) {return 0;}
int solve_sum(int n,int confidence[],int host[],int protocol[]) {return 0;}
int solve_max(int n,int confidence[],int host[],int protocol[]) {return 0;}
int findSample(int n,int confidence[],int host[],int protocol[]) {
if(n<=10) return solve_naive(n,confidence,host,protocol);
bool flag[3]={true,true,true};
for(int i=1;i<n;i++) {
for(int j=0;j<3;j++) {
if(j==protocol[i]) flag[j]&=true;
else flag[j]=false;
}
}
if(flag[0]) return solve_tree(n,confidence,host,protocol);
if(flag[1]) return solve_sum(n,confidence,host,protocol);
if(flag[2]) return solve_max(n,confidence,host,protocol);
assert(0);
}
Compilation message (stderr)
friend.cpp: In function 'int solve_naive(int, int*, int*, int*)':
friend.cpp:57:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int j=0;j<sz(took);j++) {
^
# | 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... |