이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#if defined(ONPC) && !defined(_GLIBCXX_ASSERTIONS)
#define _GLIBCXX_ASSERTIONS
#endif
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
#ifdef ONPC
#include "t_debug.cpp"
#else
#define debug(...) 42
#endif
#define allit(a) (a).begin(), (a).end()
#define sz(a) ((int) (a).size())
#include "friend.h"
using namespace std;
using ll = long long;
using vi = vector<int>;
namespace pd = __gnu_pbds;
template<typename K>
using ordered_set = pd::tree<K, pd::null_type, less<int>, pd::rb_tree_tag, pd::tree_order_statistics_node_update>;
template<typename... T>
using gp_hash_table = pd::gp_hash_table<T...>;//simple using statement gives warnings
const int INF = 1e9;
const ll INFL = 1e18;
const int N = 1e5;
const int RANDOM = chrono::high_resolution_clock::now().time_since_epoch().count();
mt19937 rng(RANDOM);
// Find out best sample
int findSample(int n, int* confidence, int* host, int* protocol) {
bool adj[10][10];
memset(adj, 0, sizeof(adj));
for (int i = 1; i < n; i++) {
if (protocol[i] == 0) {
adj[host[i]][i] = 1;
adj[i][host[i]] = 1;
}
else if (protocol[i] == 2) {
for (int j = 0; j < i; j++) {
if (j == host[i]) continue;
adj[i][j] = 1;
adj[j][i] = 1;
}
}
else {
for (int j = 0; j < i; j++) {
if (adj[j][host[i]]) {
adj[i][j] = 1;
adj[j][i] = 1;
}
}
}
}
for (int i = 0; i < n; i++) {
for (int j= 0; j <n; j++) {
cout << adj[i][j] << ' ';
}
cout << '\n';
}
ll res = 0;
for (int perm = 0; perm < (1 << n); perm++) {
ll sum = 0;
for (int i = 0; i < n; i++) {
for (int j = i+1; j < n; j++) {
if ((perm &(1<<i)) && (perm &(1<<j)) && adj[i][j]) {
goto next_perm;
}
}
}
for (int i = 0; i < n; i++) {
if (perm&(1<<i)) sum += confidence[i];
}
res = max(res, sum);
next_perm: continue;
}
return res;
}
int findSample_4(int n,int confidence[],int host[],int protocol[]){
bool adj[1000][1000];
memset(adj, 0, sizeof(adj));
for (int i = 1; i < n; i++) {
if (protocol[i] == 0) {
adj[host[i]][i] = 1;
adj[i][host[i]] = 1;
}
else {
for (int j = 0; j < i; j++) {
if (j == host[i] && protocol[i] == 1) continue;
adj[i][j] = 1;
adj[j][i] = 1;
}
}
}
ll dp[n][2];
memset(dp, -1, sizeof(dp));
function<ll(int,int,int)> dfs = [&](int i, int prev, int p) {
if (dp[i][prev] != -1) return dp[i][prev];
ll res = 0;
ll res2 = confidence[i];
for (int e = 0; e < n; e++) {
if (!adj[i][e] || e == p) continue;
res += dfs(e, 0, i);
res2 += dfs(e, 1, i);
}
if (prev == 0) res = max(res, res2);
return dp[i][prev] = res;
};
return dfs(0, 0, -1);
}
# | 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... |