Submission #582361

#TimeUsernameProblemLanguageResultExecution timeMemory
582361kamelfanger83Friend (IOI14_friend)C++17
Compilation error
0 ms0 KiB
#include <iostream>
#include <vector>
#include "friend.h"

using namespace std;

int findSample(int n, int confidence[], int host[], int protocol[]){
    if(n <= 10){
        vector<vector<bool>> cons (n, vector<bool> (n, false));
        for(int hoster = 1; hoster < n; hoster++){
            if(protocol[hoster] == 0){
                cons[hoster][host[hoster]] = true;
                cons[host[hoster]][hoster] = true;
            }
            else if(protocol[hoster] == 1){
                for(int friender = 0; friender < n; friender++){
                    if(cons[host[hoster]][friender]) cons[friender][hoster] = cons[hoster][friender] = true;
                } 
            }
            else {
                for(int friender = 0; friender < n; friender++){
                    if(cons[host[hoster]][friender]) cons[friender][hoster] = cons[hoster][friender] = true;
                } 
                cons[hoster][host[hoster]] = true;
                cons[host[hoster]][hoster] = true;
            }
        }
        int best = 0;
        for(int bitmask = 0; bitmask < (1 << n); bitmask++){
            int summ = 0;
            for(int i = 0; i < n; i++){
                for(int j = 0; j < n; j++){
                    if(cons[i][j] && ((bitmask & (1 << i)) != 0) && ((bitmask & (1 << j)) != 0)) goto no;
                }
            }
            for(int summer = 0; summer < n; summer++){
                summ += confidence[summer] * ((bitmask & (1 << summer)) != 0);
            }
            best = max(best, summ);
            no:
            ;
        }
        return best;
    }
    if(protocol[1] == 1){
        int summ = 0;
        for(int summer = 0; summer < n; summer++) summ += confidence[summer];
        return summ;
    }
    if(protocol[1] == 2){
        int maxx = 0;
        for(int maxxer = 0; maxxer < n; maxxer++) maxx = max(maxx, confidence[maxxer]);
        return maxx;
    }
    if(protocol[1] == 0){
        vector<vector<int>> children (n);
        for(int hoster = 1; hoster < n; hoster++){
            children[host[hoster]].push_back(hoster);
        }
        auto getmax = [&](auto&& self, int i){
            int bo = 0;
            int bm = confidence[i];
            for(child : children[i]){
                auto got = self(self, child);
                bo += got.first;
                bm += got.second;
            }
            bm = max(bm, bo);
            return {bm, bo};
        }
        return getmax(getmax, 0).first;
    }
}

/*int main(){
    int confidence [6] = {13, 3, 6, 20, 10, 15};
    int host [6] = {0, 0, 0, 1, 2, 0,};
    int protocol [6] = {0, 0, 1, 2, 1, 0};
    cout << findSample(6, confidence, host, protocol);
}*/

Compilation message (stderr)

friend.cpp: In lambda function:
friend.cpp:63:23: error: found ':' in nested-name-specifier, expected '::'
   63 |             for(child : children[i]){
      |                       ^
      |                       ::
friend.cpp:63:17: error: 'child' has not been declared
   63 |             for(child : children[i]){
      |                 ^~~~~
friend.cpp:69:13: error: expected primary-expression before 'return'
   69 |             return {bm, bo};
      |             ^~~~~~
friend.cpp:68:30: error: expected ')' before 'return'
   68 |             bm = max(bm, bo);
      |                              ^
      |                              )
   69 |             return {bm, bo};
      |             ~~~~~~            
friend.cpp:63:16: note: to match this '('
   63 |             for(child : children[i]){
      |                ^
friend.cpp: In function 'int findSample(int, int*, int*, int*)':
friend.cpp:71:9: error: expected ',' or ';' before 'return'
   71 |         return getmax(getmax, 0).first;
      |         ^~~~~~
friend.cpp:73:1: warning: control reaches end of non-void function [-Wreturn-type]
   73 | }
      | ^