Submission #243650

# Submission time Handle Problem Language Result Execution time Memory
243650 2020-07-01T13:31:03 Z Kubin Friend (IOI14_friend) C++17
0 / 100
6 ms 1152 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 = 0; i < n; i++)
    {
        if(protocol[i] == IAmYourFriend)
        {
            mask |= 1<<IAmYourFriend;
            conn(i, host[i]);
        }
        else if(protocol[i] == MyFriendsAreYourFriends)
        {
            mask |= 1<<MyFriendsAreYourFriends;
            for(auto u : graph[host[i]])
                conn(i, u);
        }
        else if(protocol[i] == WeAreYourFriends)
        {
            mask |= 1<<WeAreYourFriends;
            conn(i, host[i]);
            for(auto u : graph[host[i]])
                conn(i, u);
        }
    }

    if(not mask or mask == (1<<MyFriendsAreYourFriends) or 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;
    }
}

Compilation message

friend.cpp: In function 'int findSample(int, int*, int*, int*)':
friend.cpp:74:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 896 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 6 ms 1152 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -