# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
281720 | SamAnd | 친구 (IOI14_friend) | C++17 | 275 ms | 65540 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "friend.h"
#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
int n;
int conf[N];
vector<int> g[N];
int dp[N][2];
void dfs(int x, int p)
{
dp[x][1] = conf[x];
for (int i = 0; i < g[x].size(); ++i)
{
int h = g[x][i];
if (h == p)
continue;
dfs(h, x);
dp[x][0] += max(dp[h][0], dp[h][1]);
dp[x][1] += dp[h][0];
}
}
int findSample(int n, int confidence[], int host[], int protocol[])
{
::n = n;
for (int i = 0; i < n; ++i)
conf[i] = confidence[i];
for (int i = 1; i < n; ++i)
{
if (protocol[i] == 0)
{
g[host[i]].push_back(i);
g[i].push_back(host[i]);
}
else if (protocol[i] == 1)
{
for (int j = 0; j < g[host[i]].size(); ++j)
{
int h = g[host[i]][j];
g[h].push_back(i);
g[i].push_back(h);
}
}
else
{
for (int j = 0; j < g[host[i]].size(); ++j)
{
int h = g[host[i]][j];
g[h].push_back(i);
g[i].push_back(h);
}
g[host[i]].push_back(i);
g[i].push_back(host[i]);
}
}
for (int i = 0; i < n; ++i)
sort(g[i].begin(), g[i].end());
if (n > 10)
{
if (protocol[1] == 1)
{
int ans = 0;
for (int i = 0; i < n; ++i)
ans += confidence[i];
return ans;
}
if (protocol[1] == 2)
{
int ans = 0;
for (int i = 0; i < n; ++i)
ans = max(ans, confidence[i]);
return ans;
}
dfs(0, 0);
return max(dp[0][0], dp[0][1]);
}
int ans = 0;
for (int x = 0; x < (1 << n); ++x)
{
int yans = 0;
bool z = true;
for (int i = 0; i < n; ++i)
{
if (!(x & (1 << i)))
continue;
yans += confidence[i];
for (int j = 0; j < n; ++j)
{
if (!(x & (1 << j)))
continue;
if (binary_search(g[i].begin(), g[i].end(), j))
{
z = false;
break;
}
}
if (!z)
break;
}
if (z)
ans = max(ans, yans);
}
return ans;
}
컴파일 시 표준 에러 (stderr) 메시지
# | 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... |