# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
94493 |
2019-01-19T11:26:17 Z |
fjzzq2002 |
Friend (IOI14_friend) |
C++14 |
|
26 ms |
16248 KB |
#include "friend.h"
#include <bits/stdc++.h>
using namespace std;
#define SZ 666666
int val[SZ],fa[SZ],fe[SZ];
vector<int> so[SZ];
int f[SZ][2][2];
inline void cmax(int&a,int b)
{if(a<b)a=b;}
void dfs(int x)
{
int ts[2][2][2];
memset(ts,-127/2,sizeof ts);
ts[0][0][0]=0;
ts[0][1][0]=val[x];
ts[1][0][0]=0;
for(auto ch:so[x])
{
dfs(ch);
int g[2][2][2];
memset(g,-127/2,sizeof g);
if(fe[ch]==0)
{
for(int a=0;a<2;++a)
for(int b=0;b<2;++b)
for(int c=0;c<2;++c)
{
cmax(g[a][b][c],ts[a][b][c]+f[ch][b][0]);
if(!b)
cmax(g[a][b][1],ts[a][b][c]+f[ch][b][1]);
}
}
else if(fe[ch]==1)
{
for(int a=0;a<2;++a)
for(int b=0;b<2;++b)
for(int c=0;c<2;++c)
{
cmax(g[a][b][c],ts[a][b][c]+f[ch][a||c][0]);
if(!a&&!c)
cmax(g[a][1][c],ts[a][b][c]+f[ch][0][1]);
}
}
else if(fe[ch]==2)
{
for(int a=0;a<2;++a)
for(int b=0;b<2;++b)
for(int c=0;c<2;++c)
{
cmax(g[a][b][c],ts[a][b][c]+f[ch][a||b||c][0]);
if(!a&&!c&&!b)
cmax(g[a][1][1],ts[a][b][c]+f[ch][0][1]);
}
}
memcpy(ts,g,sizeof g);
}
for(int a=0;a<2;++a)
for(int b=0;b<2;++b)
f[x][a][b]=max(ts[a][b][0],ts[a][b][1]);
}
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)
fa[i]=host[i],fe[i]=protocol[i],
so[host[i]].push_back(i);
dfs(0);
return max(f[0][0][1],f[0][0][0]);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
15992 KB |
Output is correct |
2 |
Correct |
16 ms |
15992 KB |
Output is correct |
3 |
Correct |
15 ms |
15992 KB |
Output is correct |
4 |
Correct |
15 ms |
15992 KB |
Output is correct |
5 |
Correct |
17 ms |
15992 KB |
Output is correct |
6 |
Correct |
16 ms |
15992 KB |
Output is correct |
7 |
Correct |
16 ms |
15992 KB |
Output is correct |
8 |
Incorrect |
16 ms |
15992 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
15992 KB |
Output is correct |
2 |
Correct |
16 ms |
16084 KB |
Output is correct |
3 |
Correct |
15 ms |
15992 KB |
Output is correct |
4 |
Correct |
16 ms |
16120 KB |
Output is correct |
5 |
Correct |
16 ms |
16120 KB |
Output is correct |
6 |
Correct |
15 ms |
15964 KB |
Output is correct |
7 |
Correct |
15 ms |
15992 KB |
Output is correct |
8 |
Correct |
16 ms |
16120 KB |
Output is correct |
9 |
Correct |
16 ms |
16120 KB |
Output is correct |
10 |
Correct |
16 ms |
16120 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
15992 KB |
Output is correct |
2 |
Correct |
16 ms |
16120 KB |
Output is correct |
3 |
Correct |
16 ms |
15992 KB |
Output is correct |
4 |
Correct |
17 ms |
15992 KB |
Output is correct |
5 |
Correct |
16 ms |
15992 KB |
Output is correct |
6 |
Correct |
16 ms |
16064 KB |
Output is correct |
7 |
Correct |
16 ms |
15992 KB |
Output is correct |
8 |
Correct |
17 ms |
15992 KB |
Output is correct |
9 |
Correct |
16 ms |
15992 KB |
Output is correct |
10 |
Correct |
17 ms |
16120 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
15992 KB |
Output is correct |
2 |
Correct |
15 ms |
15992 KB |
Output is correct |
3 |
Correct |
16 ms |
15992 KB |
Output is correct |
4 |
Correct |
15 ms |
15996 KB |
Output is correct |
5 |
Correct |
18 ms |
16248 KB |
Output is correct |
6 |
Correct |
16 ms |
16120 KB |
Output is correct |
7 |
Correct |
16 ms |
15992 KB |
Output is correct |
8 |
Correct |
15 ms |
15992 KB |
Output is correct |
9 |
Correct |
15 ms |
15992 KB |
Output is correct |
10 |
Correct |
16 ms |
15992 KB |
Output is correct |
11 |
Correct |
16 ms |
16120 KB |
Output is correct |
12 |
Correct |
15 ms |
15992 KB |
Output is correct |
13 |
Correct |
17 ms |
15992 KB |
Output is correct |
14 |
Correct |
18 ms |
15992 KB |
Output is correct |
15 |
Correct |
16 ms |
15992 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
15992 KB |
Output is correct |
2 |
Correct |
17 ms |
16012 KB |
Output is correct |
3 |
Correct |
18 ms |
16060 KB |
Output is correct |
4 |
Correct |
12 ms |
15992 KB |
Output is correct |
5 |
Correct |
13 ms |
15992 KB |
Output is correct |
6 |
Correct |
12 ms |
15992 KB |
Output is correct |
7 |
Correct |
26 ms |
15992 KB |
Output is correct |
8 |
Correct |
16 ms |
15992 KB |
Output is correct |
9 |
Correct |
14 ms |
16248 KB |
Output is correct |
10 |
Correct |
16 ms |
16248 KB |
Output is correct |
11 |
Incorrect |
16 ms |
15992 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
16124 KB |
Output is correct |
2 |
Correct |
16 ms |
15996 KB |
Output is correct |
3 |
Correct |
13 ms |
16164 KB |
Output is correct |
4 |
Correct |
16 ms |
15992 KB |
Output is correct |
5 |
Correct |
16 ms |
15992 KB |
Output is correct |
6 |
Correct |
16 ms |
15992 KB |
Output is correct |
7 |
Incorrect |
15 ms |
15992 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |