| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 501218 | blue | 친구 (IOI14_friend) | C++17 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "friend.h"
#include <vector>
using namespace std;
// Find out best sample
int findSample(int n,int confidence[],int host[],int protocol[])
{
vector<int> Yes(n, 0), No(n, 0); //dp if person i is chosen / not chosen
for(int i = 0; i < n; i++) Yes[i] += confidence[i];
for(int i = n-1; i >= 1; i--)
{
if(protocol[i] == 0) //I am your friend
{
//yes i, yes host[i]
//no i, yes host[i]
Yes[ host[i] ] += No[i];
//yes i, no host[i]
//no i, no host[i]
No[ host[i] ] += max(Yes[i], No[i]);
}
else if(protocol[i] == 1) //My friends are your friends
{
//yes i, yes host[i]
//no i, yes host[i]
//yes i, no host[i]
Yes[ host[i] ] = max(Yes[ host[i] ], No[ host[i] ]) + max(Yes[i], No[i]));
// Yes[ host[i] ] = Yes[ host[i] ] + max(Yes[i], No[i]);
//no i, no host[i]
No[ host[i] ] += No[i];
}
else //We are your friends
{
//yes i, yes host[i]
//no i, yes host[i]
//yes i, no host[i]
Yes[ host[i] ] = max(Yes[ host[i] ] + No[i], No[ host[i] ] + Yes[i]);
//no i, no host[i]
No[ host[i] ] += No[i];
}
}
return max(Yes[0], No[0]);
}
