# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1074005 | deera | Friend (IOI14_friend) | C++14 | 357 ms | 65536 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5+5;
set<int> adj[MAXN];
// Find out best sample
int findSample(int n, int confidence[], int host[], int protocol[]){
for (int i = 0; i < n; i++) {
if (i == 0) continue;
int h = host[i];
switch (protocol[i]) {
case 0:
// I am your friend
adj[h].insert(i);
adj[i].insert(h);
break;
case 1:
// my friends are your friends
for (int f: adj[h]) {
if (h == f) continue;
adj[i].insert(f);
adj[f].insert(i);
}
break;
case 2:
// we are your friends
adj[h].insert(i);
adj[i].insert(h);
for (int f: adj[h]) {
if (h == f) continue;
adj[i].insert(f);
adj[f].insert(i);
}
break;
}
}
// a friend can't be a friend of themselves
for (int i = 0; i < n; i++) adj[i].erase(i);
// for (int i = 0; i < n; i++) {
// cerr << i << ": ";
// for (auto x: adj[i]) cerr << x << " ";
// cerr << endl;
// }
if (n <= 10) {
int max_ans = 0;
int ans = 0;
for (int i = 0; i < (1 << n); i++) {
set<int> s;
for (int j = 0; j < n; j++)
if (i & (1 << j)) s.insert(j);
bool ok = true;
for (auto x: s)
for (auto f: adj[x])
if (s.count(f)) {
ok = false;
break;
}
if (!ok) continue;
for (auto x: s) ans += confidence[x];
max_ans = max(max_ans, ans);
ans = 0;
}
return max_ans;
}
int hist[3] = {0, 0, 0};
for (int i = 0; i < n; i++) hist[protocol[i]]++;
if (hist[1] == n) {
int ans = 0;
for (int i = 0; i < n; i++) ans += confidence[i];
return ans;
}
if (hist[2] == n) {
int ans = 0;
for (int i = 0; i < n; i++) ans = max(ans, confidence[i]);
return ans;
}
}
Compilation message (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... |