이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "friend.h"
using namespace std;
int memo[1000][2], c[1000];
vector<int> adj[1000];
int dp(int x, int f, int p) {
if(memo[x][f] != -1) return memo[x][f];
int ans = (f==1?c[x]:0);
for(int i : adj[x]) if(i != p) {
if(f == 1) ans += dp(i, 0, x);
else ans += max(dp(i, 0, x), dp(i, 1, x));
}
return memo[x][f] = ans;
}
int findSample(int n, int confidence[], int host[], int protocol[]) {
bool st2 = true, st3 = true, st4 = true, st5 = true;
for(int i = 0; i < n; i++) c[i] = confidence[i];
for(int i = 1; i < n; i++) {
if(protocol[i] != 0) st4 = false;
if(protocol[i] != 1) st2 = false;
if(protocol[i] != 2) st3 = false;
if(protocol[i] == 2) st5 = false;
}
if(st2) {
int sm = 0;
for(int i = 0; i < n; i++) sm += confidence[i];
return sm;
} else if(st3) {
int mx = 0;
for(int i = 0; i < n; i++) mx = max(mx, confidence[i]);
return mx;
}
for(int i = 1; i < n; i++) {
if(protocol[i] != 0) {
for(int x : adj[host[i]]) {
adj[x].push_back(i);
adj[i].push_back(x);
}
} else if(protocol[i] != 1) {
adj[i].push_back(host[i]);
adj[host[i]].push_back(i);
}
}
if(n <= 10) {
int am[n][n], ans = 0;
memset(am, 0, sizeof(am));
for(int i = 0; i < n; i++) {
for(int j : adj[i]) am[i][j] = 1;
}
for(int i = 0; i < 1<<n; i++) {
vector<int> v;
for(int j = 0; j < n; j++) {
if(i&(1<<j)) v.push_back(j);
}
int sm = 0;
for(int j = 0; j < v.size(); j++) {
for(int k = j+1; k < v.size(); k++) {
if(k >= v.size()) break;
if(am[v[j]][v[k]]) goto ed;
}
}
for(int j = 0; j < v.size(); j++) sm += c[v[j]];
ans = max(ans, sm);
ed:;
}
return ans;
} else if(st4) {
memset(memo, -1, sizeof(memo));
return max(dp(0, 0, -1), dp(0, 1, -1));
} else if(st5) {
int ans[2], dist[n];
ans[0] = ans[1] = 0;
memset(dist, -1, sizeof(dist));
dist[0] = 0;
ans[0] += c[0];
queue<int> q;
q.push(0);
while(!q.empty()) {
int cur = q.front();
q.pop();
for(int i : adj[cur]) {
if(dist[i] != -1) continue;
dist[i] = dist[cur]^1;
ans[dist[i]] += c[i];
q.push(i);
}
}
return max(ans[0], ans[1]);
}
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
friend.cpp: In function 'int findSample(int, int*, int*, int*)':
friend.cpp:58:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
58 | for(int j = 0; j < v.size(); j++) {
| ~~^~~~~~~~~~
friend.cpp:59:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
59 | for(int k = j+1; k < v.size(); k++) {
| ~~^~~~~~~~~~
friend.cpp:60:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
60 | if(k >= v.size()) break;
| ~~^~~~~~~~~~~
friend.cpp:64:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
64 | for(int j = 0; j < v.size(); j++) sm += c[v[j]];
| ~~^~~~~~~~~~
# | 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... |