# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
93803 |
2019-01-11T12:56:20 Z |
Bodo171 |
Friend (IOI14_friend) |
C++14 |
|
85 ms |
12024 KB |
#include "friend.h"
#include <vector>
#include <iostream>
// Find out best sample
using namespace std;
const int nmax=100005;
vector<int> v[nmax],ad[nmax],inloc[nmax];
int sum[nmax][2],best[nmax][2];
int a[nmax],val[nmax];
int nr,p,tip;
void dfs(int x)
{
for(int i=0;i<v[x].size();i++)
dfs(v[x][i]);
for(int i=0;i<inloc[x].size();i++)
dfs(inloc[x][i]);
for(int i=0;i<ad[x].size();i++)
dfs(ad[x][i]);
nr=0;
for(int i=0;i<v[x].size();i++)
{
a[++nr]=v[x][i];
sum[nr][0]=sum[nr-1][0]+best[a[nr]][0];
sum[nr][1]=sum[nr-1][1]+max(best[a[nr]][0],best[a[nr]][1]);
}
int totad=0,totinloc=0;
for(int i=0;i<ad[x].size();i++)
totad+=best[ad[x][i]][0];
for(int i=0;i<inloc[x].size();i++)
totinloc+=best[inloc[x][i]][0];
best[x][1]=sum[nr][0]+val[x]+totad+totinloc;
for(int i=0;i<ad[x].size();i++)
{
p=0;
while(a[p]<=ad[x][i]&&p<=nr)
p++;
p--;
best[x][1]=max(best[x][1],sum[p][0]+sum[nr][1]-sum[p][1]+best[ad[x][i]][1]+totad+totinloc-best[ad[x][i]][0]);
best[x][1]=max(best[x][1],sum[nr][0]+val[x]+best[ad[x][i]][1]+totad+totinloc-best[ad[x][i]][0]);
totad+=best[ad[x][i]][1]-best[ad[x][i]][0];
}
totad=0;
for(int i=0;i<ad[x].size();i++)
totad+=best[ad[x][i]][0];
for(int i=0;i<inloc[x].size();i++)
{
p=0;
while(a[p]<=inloc[x][i]&&p<=nr)
p++;
p--;
best[x][1]=max(best[x][1],best[inloc[x][i]][1]+sum[nr][1]-sum[p][1]+sum[p][0]+totad+totinloc-best[inloc[x][i]][0]);
}
for(int i=0;i<v[x].size();i++)
best[x][0]+=max(best[v[x][i]][0],best[v[x][i]][1]);
for(int i=0;i<ad[x].size();i++)
best[x][0]+=best[ad[x][i]][0];
for(int i=0;i<inloc[x].size();i++)
best[x][0]+=best[inloc[x][i]][0];
}
int findSample(int n,int confidence[],int host[],int protocol[]){
for(int i=0;i<n;i++)
val[i]=confidence[i];
for(int i=1;i<n;i++)
{
tip=protocol[i];
if(tip==0)
{
v[host[i]].push_back(i);
}
if(tip==1)
{
ad[host[i]].push_back(i);
}
if(tip==2)
{
inloc[host[i]].push_back(i);
}
}
dfs(0);
return max(best[0][0],best[0][1]);
}
Compilation message
friend.cpp: In function 'void dfs(int)':
friend.cpp:13:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<v[x].size();i++)
~^~~~~~~~~~~~
friend.cpp:15:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<inloc[x].size();i++)
~^~~~~~~~~~~~~~~~
friend.cpp:17:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<ad[x].size();i++)
~^~~~~~~~~~~~~
friend.cpp:20:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<v[x].size();i++)
~^~~~~~~~~~~~
friend.cpp:27:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<ad[x].size();i++)
~^~~~~~~~~~~~~
friend.cpp:29:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<inloc[x].size();i++)
~^~~~~~~~~~~~~~~~
friend.cpp:32:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<ad[x].size();i++)
~^~~~~~~~~~~~~
friend.cpp:43:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<ad[x].size();i++)
~^~~~~~~~~~~~~
friend.cpp:45:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<inloc[x].size();i++)
~^~~~~~~~~~~~~~~~
friend.cpp:53:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<v[x].size();i++)
~^~~~~~~~~~~~
friend.cpp:55:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<ad[x].size();i++)
~^~~~~~~~~~~~~
friend.cpp:57:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<inloc[x].size();i++)
~^~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
7416 KB |
Output is correct |
2 |
Correct |
6 ms |
7416 KB |
Output is correct |
3 |
Correct |
6 ms |
7416 KB |
Output is correct |
4 |
Correct |
6 ms |
7416 KB |
Output is correct |
5 |
Correct |
6 ms |
7420 KB |
Output is correct |
6 |
Correct |
6 ms |
7288 KB |
Output is correct |
7 |
Correct |
6 ms |
7416 KB |
Output is correct |
8 |
Correct |
7 ms |
7416 KB |
Output is correct |
9 |
Correct |
7 ms |
7416 KB |
Output is correct |
10 |
Correct |
7 ms |
7416 KB |
Output is correct |
11 |
Correct |
6 ms |
7416 KB |
Output is correct |
12 |
Correct |
6 ms |
7416 KB |
Output is correct |
13 |
Correct |
7 ms |
7416 KB |
Output is correct |
14 |
Correct |
7 ms |
7420 KB |
Output is correct |
15 |
Correct |
6 ms |
7416 KB |
Output is correct |
16 |
Correct |
6 ms |
7416 KB |
Output is correct |
17 |
Incorrect |
7 ms |
7416 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
7464 KB |
Output is correct |
2 |
Correct |
6 ms |
7416 KB |
Output is correct |
3 |
Correct |
7 ms |
7416 KB |
Output is correct |
4 |
Correct |
7 ms |
7416 KB |
Output is correct |
5 |
Correct |
7 ms |
7416 KB |
Output is correct |
6 |
Correct |
7 ms |
7416 KB |
Output is correct |
7 |
Correct |
6 ms |
7416 KB |
Output is correct |
8 |
Correct |
8 ms |
7416 KB |
Output is correct |
9 |
Correct |
7 ms |
7416 KB |
Output is correct |
10 |
Correct |
8 ms |
7464 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
7416 KB |
Output is correct |
2 |
Correct |
8 ms |
7416 KB |
Output is correct |
3 |
Correct |
6 ms |
7416 KB |
Output is correct |
4 |
Correct |
7 ms |
7416 KB |
Output is correct |
5 |
Correct |
7 ms |
7416 KB |
Output is correct |
6 |
Correct |
6 ms |
7416 KB |
Output is correct |
7 |
Correct |
6 ms |
7416 KB |
Output is correct |
8 |
Correct |
7 ms |
7420 KB |
Output is correct |
9 |
Correct |
6 ms |
7416 KB |
Output is correct |
10 |
Correct |
7 ms |
7416 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
7416 KB |
Output is correct |
2 |
Correct |
7 ms |
7420 KB |
Output is correct |
3 |
Correct |
7 ms |
7416 KB |
Output is correct |
4 |
Correct |
1 ms |
7416 KB |
Output is correct |
5 |
Correct |
7 ms |
7544 KB |
Output is correct |
6 |
Correct |
7 ms |
7416 KB |
Output is correct |
7 |
Correct |
7 ms |
7416 KB |
Output is correct |
8 |
Correct |
7 ms |
7416 KB |
Output is correct |
9 |
Correct |
7 ms |
7416 KB |
Output is correct |
10 |
Correct |
7 ms |
7416 KB |
Output is correct |
11 |
Correct |
7 ms |
7416 KB |
Output is correct |
12 |
Correct |
8 ms |
7416 KB |
Output is correct |
13 |
Correct |
8 ms |
7416 KB |
Output is correct |
14 |
Correct |
8 ms |
7416 KB |
Output is correct |
15 |
Correct |
8 ms |
7416 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
7420 KB |
Output is correct |
2 |
Correct |
7 ms |
7416 KB |
Output is correct |
3 |
Correct |
8 ms |
7416 KB |
Output is correct |
4 |
Correct |
7 ms |
7416 KB |
Output is correct |
5 |
Correct |
7 ms |
7416 KB |
Output is correct |
6 |
Correct |
8 ms |
7416 KB |
Output is correct |
7 |
Correct |
7 ms |
7416 KB |
Output is correct |
8 |
Correct |
7 ms |
7416 KB |
Output is correct |
9 |
Correct |
8 ms |
7544 KB |
Output is correct |
10 |
Correct |
8 ms |
7544 KB |
Output is correct |
11 |
Incorrect |
8 ms |
7420 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
7404 KB |
Output is correct |
2 |
Correct |
9 ms |
7424 KB |
Output is correct |
3 |
Correct |
8 ms |
7416 KB |
Output is correct |
4 |
Correct |
7 ms |
7416 KB |
Output is correct |
5 |
Correct |
7 ms |
7416 KB |
Output is correct |
6 |
Correct |
6 ms |
7416 KB |
Output is correct |
7 |
Correct |
7 ms |
7416 KB |
Output is correct |
8 |
Correct |
7 ms |
7416 KB |
Output is correct |
9 |
Correct |
7 ms |
7416 KB |
Output is correct |
10 |
Correct |
7 ms |
7416 KB |
Output is correct |
11 |
Correct |
8 ms |
7416 KB |
Output is correct |
12 |
Incorrect |
85 ms |
12024 KB |
Output isn't correct |
13 |
Halted |
0 ms |
0 KB |
- |