Submission #671476

# Submission time Handle Problem Language Result Execution time Memory
671476 2022-12-13T05:49:11 Z user149 Easter Eggs (info1cup17_eastereggs) C++14
Compilation error
0 ms 0 KB
#include<bits/stdc++.h>
#include "grader.h"
using namespace std;

using pii=pair<int,int>;


int N;
vector<int> adjlist[555];

bool seen[555];
vector<int> preorder={-1};

void init(){
    fill(seen,seen+555,0);
    fill(adjlist,adjlist+555,{});
    preorder={-1};
}

void dfs(int node){
    seen[node]=1;
    preorder.push_back(node);#include<bits/stdc++.h>
#include "grader.h"
using namespace std;

using pii=pair<int,int>;


int N;
vector<int> adjlist[555];

bool seen[555];
vector<int> preorder={-1};

void init(){
    fill(seen,seen+555,0);
    fill(adjlist,adjlist+555,(vector<int>){});
    preorder={-1};
}

void dfs(int node){
    seen[node]=1;
    preorder.push_back(node);

    for(int child:adjlist[node]){
        if(!seen[child]) dfs(child);
    }
}

int bsearch(){
    int lo=1;
    int hi=N;

    vector<int> query_vector; // always a prefix [1..i]

    while(lo!=hi){
        int mid=(lo+hi)/2;
        while(query_vector[query_vector.size()-1]>lo) query_vector.pop_back();

        for(int i=lo+1;i<=mid;i++){
            query_vector.push_back(i);
        }

        if(query(query_vector)) hi=mid;
        else lo=mid+1;
    }

    return lo;
}

int findEgg(int _N, vector<pii> edges){
    N=_N;
    init();
    for(pii i:edges){
        int a,b;
        tie(a,b)=i;
        adjlist[a].push_back(b);
        adjlist[b].push_back(a);
    }
    dfs(1);

    return bsearch();
}

    for(int child:adjlist[node]){
        if(!seen[child]) dfs(child);
    }
}

int bsearch(){
    int lo=1;
    int hi=N;

    vector<int> query_vector; // always a prefix [1..i]

    while(lo!=hi){
        int mid=(lo+hi)/2;
        while(query_vector[query_vector.size()-1]>lo) query_vector.pop_back();

        for(int i=lo+1;i<=mid;i++){
            query_vector.push_back(i);
        }

        if(query(query_vector)) hi=mid;
        else lo=mid+1;
    }

    return lo;
}

int findEgg(int _N, vector<pii> edges){
    N=_N;
    init();
    for(pii i:edges){
        int a,b;
        tie(a,b)=i;
        adjlist[a].push_back(b);
        adjlist[b].push_back(a);
    }
    dfs(1);

    return bsearch();
}

Compilation message

eastereggs.cpp:22:30: error: stray '#' in program
   22 |     preorder.push_back(node);#include<bits/stdc++.h>
      |                              ^
eastereggs.cpp: In function 'void init()':
eastereggs.cpp:16:32: error: no matching function for call to 'fill(std::vector<int> [555], std::vector<int>*, <brace-enclosed initializer list>)'
   16 |     fill(adjlist,adjlist+555,{});
      |                                ^
In file included from /usr/include/c++/10/bits/char_traits.h:39,
                 from /usr/include/c++/10/ios:40,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from eastereggs.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:937:5: note: candidate: 'template<class _ForwardIterator, class _Tp> void std::fill(_ForwardIterator, _ForwardIterator, const _Tp&)'
  937 |     fill(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value)
      |     ^~~~
/usr/include/c++/10/bits/stl_algobase.h:937:5: note:   template argument deduction/substitution failed:
eastereggs.cpp:16:32: note:   couldn't deduce template parameter '_Tp'
   16 |     fill(adjlist,adjlist+555,{});
      |                                ^
In file included from /usr/include/c++/10/vector:68,
                 from /usr/include/c++/10/queue:61,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:86,
                 from eastereggs.cpp:1:
/usr/include/c++/10/bits/stl_bvector.h:434:3: note: candidate: 'void std::fill(std::_Bit_iterator, std::_Bit_iterator, const bool&)'
  434 |   fill(_Bit_iterator __first, _Bit_iterator __last, const bool& __x)
      |   ^~~~
/usr/include/c++/10/bits/stl_bvector.h:434:22: note:   no known conversion for argument 1 from 'std::vector<int> [555]' to 'std::_Bit_iterator'
  434 |   fill(_Bit_iterator __first, _Bit_iterator __last, const bool& __x)
      |        ~~~~~~~~~~~~~~^~~~~~~
eastereggs.cpp: In function 'void dfs(int)':
eastereggs.cpp:22:31: error: 'include' was not declared in this scope
   22 |     preorder.push_back(node);#include<bits/stdc++.h>
      |                               ^~~~~~~
eastereggs.cpp:22:39: error: 'bits' was not declared in this scope
   22 |     preorder.push_back(node);#include<bits/stdc++.h>
      |                                       ^~~~
eastereggs.cpp:22:44: error: 'stdc' was not declared in this scope; did you mean 'std'?
   22 |     preorder.push_back(node);#include<bits/stdc++.h>
      |                                            ^~~~
      |                                            std
In file included from eastereggs.cpp:23:
grader.h:3:1: error: expected primary-expression before 'using'
    3 | using namespace std;
      | ^~~~~
eastereggs.cpp:35:12: error: a function-definition is not allowed here before '{' token
   35 | void init(){
      |            ^
eastereggs.cpp:41:19: error: a function-definition is not allowed here before '{' token
   41 | void dfs(int node){
      |                   ^
eastereggs.cpp:50:14: error: a function-definition is not allowed here before '{' token
   50 | int bsearch(){
      |              ^
eastereggs.cpp:71:39: error: a function-definition is not allowed here before '{' token
   71 | int findEgg(int _N, vector<pii> edges){
      |                                       ^
eastereggs.cpp:29:5: warning: unused variable 'N' [-Wunused-variable]
   29 | int N;
      |     ^