# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
243653 |
2020-07-01T13:42:24 Z |
Kubin |
Friend (IOI14_friend) |
C++17 |
|
162 ms |
65540 KB |
#include <bits/stdc++.h>
using namespace std;
enum Protocol
{
IAmYourFriend = 0,
MyFriendsAreYourFriends = 1,
WeAreYourFriends = 2
};
int findSample(int _n, int val[], int host[], int protocol[])
{
size_t n = _n;
vector<vector<size_t>> graph(n);
auto conn = [&](size_t u, size_t v) {
graph[u].push_back(v);
graph[v].push_back(u);
};
uint mask = 0;
for(size_t i = 1; i < n; i++)
{
mask |= 1<<protocol[i];
if(protocol[i] == IAmYourFriend)
conn(i, host[i]);
else if(protocol[i] == MyFriendsAreYourFriends)
for(auto u : graph[host[i]])
conn(i, u);
else if(protocol[i] == WeAreYourFriends)
{
for(auto u : graph[host[i]])
conn(i, u);
conn(i, host[i]);
}
}
if(not mask or mask == (1<<MyFriendsAreYourFriends))
return accumulate(val, val + n, 0);
else if(mask == (1<<WeAreYourFriends))
return *max_element(val, val + n);
/*
else if(mask == (1<<IAmYourFriend))
{
// host is parent
}
else if(mask == ((1<<IAmYourFriend) | (1<<MyFriendsAreYourFriends)))
{
// graph is bipartite
}
*/
else
{
int result = 0;
for(size_t s = 0; s < (1u << n); s++)
{
int curr = 0;
bool ok = true;
for(size_t i = 0; i < n; i++) if(s & (1 << i))
{
curr += val[i];
for(size_t j = 0; j < n; j++) if(s & (1 << j))
if(find(graph[i].begin(), graph[i].end(), j) != graph[i].end())
ok = false;
}
if(ok)
result = max(result, curr);
}
return result;
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
4 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
4 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
384 KB |
Output is correct |
13 |
Correct |
5 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
4 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
384 KB |
Output is correct |
17 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
2048 KB |
Output is correct |
2 |
Correct |
15 ms |
7936 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
11 ms |
5760 KB |
Output is correct |
5 |
Correct |
15 ms |
7936 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
6 ms |
1408 KB |
Output is correct |
8 |
Correct |
7 ms |
1792 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
15 ms |
8448 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Incorrect |
40 ms |
384 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
4 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
4 ms |
384 KB |
Output is correct |
8 |
Correct |
4 ms |
384 KB |
Output is correct |
9 |
Incorrect |
39 ms |
384 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
4 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
4 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
4 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Runtime error |
162 ms |
65540 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
13 |
Halted |
0 ms |
0 KB |
- |