# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
582310 |
2022-06-23T16:03:26 Z |
Josia |
Friend (IOI14_friend) |
C++14 |
|
29 ms |
7380 KB |
#include <bits/stdc++.h>
#include "friend.h"
using namespace std;
// vector<vector<int>> friendGraph;
// vector<int> value;
// vector<int> visited;
// int dfs(int v) {
// if (visited[v]) return 0;
// visited[v] = 1;
// int res = value[v];
// for (int i: friendGraph[v]) {
// res = max(res, dfs(i));
// }
// return res;
// }
// Find out best sample
int findSample(int n,int confidence[],int host[],int protocol[]){
vector<set<int>> friends(n);
if (n<=10) {
for (int i = 1; i<n; i++) {
int v = host[i];
int type = protocol[i];
// int value = confidence[i];
if (type == 0) {
for (int j = 0; j<i; j++) {
if (j == v) {
friends[i].insert(j);
friends[j].insert(i);
// friendGraph[j].push_back(i);
// friendGraph[i].push_back(j);
continue;
}
}
}
if (type == 1) {
for (int j = 0; j<i; j++) {
if (friends[v].count(j)) {
friends[i].insert(j);
friends[j].insert(i);
// friendGraph[j].push_back(i);
// friendGraph[i].push_back(j);
continue;
}
}
}
if (type == 2) {
for (int j = 0; j<i; j++) {
if (friends[v].count(j) || j == v) {
friends[i].insert(j);
friends[j].insert(i);
// friendGraph[j].push_back(i);
// friendGraph[i].push_back(j);
continue;
}
}
}
}
int res = 0;
for (int i = 0; i<(1<<n); i++) {
int tmp = 0;
vector<int> nodes;
for (int j = 0; j<n; j++) {
if (i & (1<<j)) nodes.push_back(j);
}
bool poss = 1;
for (int i: nodes) {
for (int j: nodes) {
if (friends[i].count(j)) poss = 0;
}
}
if (!poss) continue;
for (int i: nodes) {
tmp += confidence[i];
}
res = max(res, tmp);
}
return res;
}
// friendGraph.clear();
// // friendGraph.clear();
// friendGraph.resize(n);
// // friendGraph.resize(n);
// visited.assign(n, 0);
// value.assign(n, 0);
// for (int i = 0; i<n; i++) {
// value[i] = confidence[i];
// }
// vector<set<int>> friends(n);
// for (int i = 0; i<n; i++) {
// int v = host[i];
// int type = protocol[i];
// // int value = confidence[i];
// if (type == 0) {
// for (int j = 0; j<i; j++) {
// if (j == v) {
// friends[i].insert(j);
// friends[j].insert(i);
// friendGraph[j].push_back(i);
// friendGraph[i].push_back(j);
// continue;
// }
// }
// }
// if (type == 1) {
// for (int j = 0; j<i; j++) {
// if (friends[v].count(j)) {
// friends[i].insert(j);
// friends[j].insert(i);
// friendGraph[j].push_back(i);
// friendGraph[i].push_back(j);
// continue;
// }
// }
// }
// if (type == 2) {
// for (int j = 0; j<i; j++) {
// if (friends[v].count(j) || j == v) {
// friends[i].insert(j);
// friends[j].insert(i);
// friendGraph[j].push_back(i);
// friendGraph[i].push_back(j);
// continue;
// }
// }
// }
// }
// int res = 0;
// for (int i = 0; i<n; i++) {
// res += dfs(i);
// }
int res = 0;
if (protocol[1] == 1) {
for (int i = 0; i<n; i++) {
res += confidence[i];
}
}
if (protocol[1] == 2) {
for (int i = 0; i<n; i++) {
res = max(res, confidence[i]);
}
}
return res;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
308 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
304 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
308 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
304 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
328 KB |
Output is correct |
5 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
304 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
312 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
308 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
304 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Incorrect |
29 ms |
7380 KB |
Output isn't correct |
13 |
Halted |
0 ms |
0 KB |
- |