# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
114384 | E869120 | 친구 (IOI14_friend) | C++14 | 33 ms | 5212 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "friend.h"
#include <bits/stdc++.h>
using namespace std;
vector<int> G[100009];
int dp[100009][2], A[100009];
void dfs(int pos) {
int m1 = 0, m2 = 0;
for (int i = 0; i < G[pos].size(); i++) {
dfs(G[pos][i]);
m1 += max(dp[G[pos][i]][0], dp[G[pos][i]][1]);
m2 += dp[G[pos][i]][1];
}
m2 += A[pos];
dp[pos][0] = m2; dp[pos][1] = m1;
}
// Find out best sample
int findSample(int n,int confidence[],int host[],int protocol[]){
int bit = 0;
for (int i = 1; i <= n - 1; i++) bit |= (1 << protocol[i]);
if (bit == 1) {
// Subtask 4.
for (int i = 0; i < n; i++) A[i] = confidence[i];
for (int i = 1; i <= n - 1; i++) G[host[i]].push_back(i);
dfs(0);
return max(dp[0][0], dp[0][1]);
}
if (bit == 2) {
// Subtask 2.
int sum = 0; for (int i = 0; i < n; i++) sum += confidence[i];
return sum;
}
if (bit == 4) {
// Subtask 3.
int sum = 0; for (int i = 0; i < n; i++) sum = max(sum, confidence[i]);
return sum;
}
if (n <= 10) {
// Subtask 1.
for (int i = 1; i <= n - 1; i++) {
if (protocol[i] == 0 || protocol[i] == 2) {
G[host[i]].push_back(i);
G[i].push_back(host[i]);
}
if (protocol[i] == 1 || protocol[i] == 2) {
for (int pos : G[host[i]]) {
if (pos == i) continue;
G[pos].push_back(i);
G[i].push_back(pos);
}
}
}
int ans = 0;
for (int i = 0; i < (1 << n); i++) {
bool flag = false; int sum = 0;
int bit[10]; for (int j = 0; j < n; j++) { bit[j] = (i / (1 << j)) % 2; sum += bit[j] * confidence[j]; }
for (int j = 0; j < n; j++) {
for (int k = 0; k < G[j].size(); k++) { if (bit[j] == 1 && bit[G[j][k]] == 1) flag = true; }
}
if (flag == false) ans = max(ans, sum);
}
return ans;
}
return -1;
}
컴파일 시 표준 에러 (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... |