Submission #1073981

#TimeUsernameProblemLanguageResultExecution timeMemory
1073981MalixFriend (IOI14_friend)C++14
11 / 100
116 ms65536 KiB
#include "friend.h" #include <bits/stdc++.h> using namespace std; #define REP(a,b,c) for(int a=b;a<c;a++) #define F first #define S second #define PB push_back typedef long long ll; typedef vector<int> vi; typedef vector<vi> vii; typedef pair<int,int> pi; vii a; int n; int brute(int confidence[]){ int m=pow(2,n); int ans=0; REP(i,0,n)sort(a[i].begin(),a[i].end()); REP(i,1,m){ int k=0; set<int> st; REP(j,0,n){ if(i&(1<<j))st.insert(j); } bool flag=1; for(auto u:st){ for(auto v:a[u]){ if(st.count(v)!=0)flag=0; } } for(auto u:st)k+=confidence[u]; if(flag)ans=max(ans,k); } return ans; } // Find out best sample int findSample(int N,int confidence[],int host[],int protocol[]){ n=N; bool flag=1; REP(i,1,n)if(protocol[i]!=1)flag=0; if(flag)return *max_element(confidence,confidence+n); a.resize(n); REP(i,1,n){ int pos=host[i]; if(protocol[i]==0||protocol[i]==2){ a[pos].PB(i); a[i].PB(pos); } if(protocol[i]==1||protocol[i]==2){ for(auto u:a[pos])if(u!=i){ a[u].PB(i); a[i].PB(u); } } } if(n<=10)return brute(confidence); vi t(n,-1); t[0]=0; queue<pi> pq; pq.push({0,0}); while(!pq.empty()){ int x=pq.front().F; pq.pop(); for(auto u:a[x])if(t[u]==-1){ t[u]=1-t[x]; pq.push({u,t[u]}); } } int l=0,r=0; REP(i,0,n){ if(t[i]==0)l+=confidence[i]; else r+=confidence[i]; } return max(l,r); }
#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...