Submission #666671

# Submission time Handle Problem Language Result Execution time Memory
666671 2022-11-29T09:23:31 Z divad Easter Eggs (info1cup17_eastereggs) C++17
Compilation error
0 ms 0 KB
#include <vector>
#include <deque>
#include "grader.h"
#define MAX 522
using namespace std;
int vf[MAX];
vector<int> v[MAX];
int n,x,y;

/*int query(vector<int> islands){
    for(auto it: islands){
        if(it == 3){
            return true;
        }
    }
    return false;
}*/

vector<int> bfs(int N, vector< pair<int, int> > bridges){
    memset(vf, 0, sizeof(vf));
    for(int i = 0; i < MAX; i++){
        v[i].clear();
    }
    for(auto [x, y]: bridges){
        v[x].push_back(y);
        v[y].push_back(x);
    }
    deque<int> coada;
    vf[1] = 1;
    int maxi = 0;
    coada.push_back(1);
    while(!coada.empty()){
        int nod = coada.back();
        for(auto vecin: v[nod]){
            if(vf[vecin] == 0){
                vf[vecin] = 1+vf[nod];
                maxi = max(maxi, vf[vecin]);
                coada.push_front(vecin);
            }
        }
        coada.pop_back();
    }
    vector<int> ans;
    for(int i = 1; i <= maxi; i++){
        for(int j = 0; j <= N; j++){
            if(vf[j] == i){
                ans.push_back(j);
            }
        }
    }
    return ans;
}

int findEgg(int N, vector< pair<int, int> > bridges){
    vector<int> parcurgere = bfs(N, bridges);
    /*cout << "parcurgere = ";
    for(auto it: parcurgere){
        cout << it << " ";
    }
    cout << "\n";*/
    /// 0 0 0 0 1 1 1 1
    ///         ^
    int st = 0, dr = parcurgere.size()-2;
    int ans = parcurgere[parcurgere.end()-1];
    while(st <= dr){
        int mid = (st+dr)/2;
        vector<int> partit;
        for(int i = 0; i <= mid; i++){
            partit.push_back(parcurgere[i]);
        }
        if(query(partit)){
            ans = parcurgere[mid];
            dr = mid-1;
        }else{
            st = mid+1;
        }
    }
    return ans;
}

Compilation message

eastereggs.cpp: In function 'int findEgg(int, std::vector<std::pair<int, int> >)':
eastereggs.cpp:64:25: error: no match for 'operator[]' (operand types are 'std::vector<int>' and '__gnu_cxx::__normal_iterator<int*, std::vector<int> >')
   64 |     int ans = parcurgere[parcurgere.end()-1];
      |                         ^
In file included from /usr/include/c++/10/vector:67,
                 from eastereggs.cpp:1:
/usr/include/c++/10/bits/stl_vector.h:1043:7: note: candidate: 'std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::operator[](std::vector<_Tp, _Alloc>::size_type) [with _Tp = int; _Alloc = std::allocator<int>; std::vector<_Tp, _Alloc>::reference = int&; std::vector<_Tp, _Alloc>::size_type = long unsigned int]'
 1043 |       operator[](size_type __n) _GLIBCXX_NOEXCEPT
      |       ^~~~~~~~
/usr/include/c++/10/bits/stl_vector.h:1043:28: note:   no known conversion for argument 1 from '__gnu_cxx::__normal_iterator<int*, std::vector<int> >' to 'std::vector<int>::size_type' {aka 'long unsigned int'}
 1043 |       operator[](size_type __n) _GLIBCXX_NOEXCEPT
      |                  ~~~~~~~~~~^~~
/usr/include/c++/10/bits/stl_vector.h:1061:7: note: candidate: 'std::vector<_Tp, _Alloc>::const_reference std::vector<_Tp, _Alloc>::operator[](std::vector<_Tp, _Alloc>::size_type) const [with _Tp = int; _Alloc = std::allocator<int>; std::vector<_Tp, _Alloc>::const_reference = const int&; std::vector<_Tp, _Alloc>::size_type = long unsigned int]'
 1061 |       operator[](size_type __n) const _GLIBCXX_NOEXCEPT
      |       ^~~~~~~~
/usr/include/c++/10/bits/stl_vector.h:1061:28: note:   no known conversion for argument 1 from '__gnu_cxx::__normal_iterator<int*, std::vector<int> >' to 'std::vector<int>::size_type' {aka 'long unsigned int'}
 1061 |       operator[](size_type __n) const _GLIBCXX_NOEXCEPT
      |                  ~~~~~~~~~~^~~