# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
69768 | E869120 | Friend (IOI14_friend) | C++14 | 13 ms | 4604 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "friend.h"
#include <algorithm>
#include <vector>
#include <iostream>
#include <cassert>
using namespace std;
// Find out best sample
int p[1009][1009], N; vector<int>x[1009];
int dp[1009][2], conf[1009], col[1009];
void dfs(int pos) {
for (int i = 0; i < x[pos].size(); i++) dfs(x[pos][i]);
for (int i = 0; i < x[pos].size(); i++) dp[pos][0] += max(dp[x[pos][i]][0], dp[x[pos][i]][1]);
for (int i = 0; i < x[pos].size(); i++) dp[pos][1] += dp[x[pos][i]][0];
dp[pos][1] += conf[pos];
}
int G1 = 0, G2 = 0;
void dfs2(int pos, int dep) {
if (col[pos] >= 0) {
assert(col[pos] == dep);
return;
}
col[pos] = dep;
if (dep == 0) G1++; if (dep == 1) G2++;
for (int i = 0; i < N; i++) {
if (p[pos][i] == 1) dfs2(i, dep ^ 1);
}
}
int findSample(int n, int confidence[], int host[], int protocol[]) {
N = n;
if (n <= 1000) {
for (int i = 1; i <= n - 1; i++) {
if (protocol[i] == 0 || protocol[i] == 2) {
p[host[i]][i] = 1;
p[i][host[i]] = 1;
}
if (protocol[i] == 1 || protocol[i] == 2) {
for (int j = 0; j < n; j++) {
if (p[host[i]][j] == 1) {
p[j][i] = 1; p[i][j] = 1;
}
}
}
}
}
if (n <= 2) {
int maxn = 0;
for (int i = 0; i < (1 << n); i++) {
vector<int>vec;
for (int j = 0; j < n; j++) { if ((i / (1 << j)) % 2 == 1) vec.push_back(j); }
bool OK = true;
for (int j = 0; j < vec.size(); j++) {
for (int k = j + 1; k < vec.size(); k++) {
if (p[vec[j]][vec[k]] == 1) OK = false;
}
}
if (OK == false) continue;
int bit = 0; for (int j = 0; j < vec.size(); j++) bit += confidence[vec[j]];
maxn = max(maxn, bit);
}
return maxn;
}
else {
int c[3] = { 0,0,0 }; for (int i = 1; i < n; i++) c[protocol[i]] = 1;
int bit = c[0] * 1 + c[1] * 2 + c[2] * 4;
for (int i = 0; i < n; i++) conf[i] = confidence[i];
if (bit == 4) {
int maxn = 0;
for (int i = 0; i < n; i++) maxn = max(maxn, confidence[i]);
return maxn;
}
if (bit == 2) {
int cnts = 0;
for (int i = 0; i < n; i++) cnts += confidence[i];
return cnts;
}
if (bit == 1) {
for (int i = 1; i < n; i++) { x[host[i]].push_back(i); }
dfs(0);
return max(dp[0][0], dp[0][1]);
}
if (bit == 3) {
for (int i = 0; i < n; i++) col[i] = -1;
int ret = 0;
for (int i = 0; i < n; i++) {
if (col[i] >= 0) continue;
G1 = 0; G2 = 0;
dfs2(i, 0);
ret += max(G1, G2);
}
return ret;
}
}
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... |