Submission #289441

#TimeUsernameProblemLanguageResultExecution timeMemory
289441eohomegrownapps고대 책들 (IOI17_books)C++14
Compilation error
0 ms0 KiB
#include "books.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; vector<ll> cycle; vector<ll> p; ll n; ll minc = 1e9; ll maxc = -1e9; ll findcycle(ll i, ll ptr){ cycle[i] = ptr; minc=min(minc,i); maxc=max(maxc,i); if (cycle[p[i]]!=-1){ return abs(i-p[i]); } else { return abs(i-p[i]) + findcycle(p[i], ptr); } } ll minimum_walk(std::vector<int> px, int s) { p = px; n = p.size(); cycle.resize(n,-1); ll cycledist = 0; ll ptr = 0; vector<ll> cyclewidth(n); for (ll i = 0; i<n; i++){ if (cycle[i]!=-1){continue;} minc=1e9;maxc=-1e9; ll dist = findcycle(i,ptr); cyclewidth[minc]++; cyclewidth[maxc]--; cycledist+=dist; ptr++; } ll prev = 0; bool iszero = true; ll ctr = 0; for (ll i = 0; i<n; i++){ ctr+=cyclewidth[i]; if (iszero&&ctr>0){ cycledist+=2*(i-prev); iszero = false; } else if ((!iszero)&&ctr==0){ prev = i; iszero = true; } } return cycledist; }

Compilation message (stderr)

books.cpp: In function 'll minimum_walk(std::vector<int>, int)':
books.cpp:26:6: error: no match for 'operator=' (operand types are 'std::vector<long long int>' and 'std::vector<int>')
   26 |  p = px;
      |      ^~
In file included from /usr/include/c++/9/vector:72,
                 from books.h:1,
                 from books.cpp:1:
/usr/include/c++/9/bits/vector.tcc:198:5: note: candidate: 'std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(const std::vector<_Tp, _Alloc>&) [with _Tp = long long int; _Alloc = std::allocator<long long int>]'
  198 |     vector<_Tp, _Alloc>::
      |     ^~~~~~~~~~~~~~~~~~~
/usr/include/c++/9/bits/vector.tcc:199:42: note:   no known conversion for argument 1 from 'std::vector<int>' to 'const std::vector<long long int>&'
  199 |     operator=(const vector<_Tp, _Alloc>& __x)
      |               ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
In file included from /usr/include/c++/9/vector:67,
                 from books.h:1,
                 from books.cpp:1:
/usr/include/c++/9/bits/stl_vector.h:706:7: note: candidate: 'std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(std::vector<_Tp, _Alloc>&&) [with _Tp = long long int; _Alloc = std::allocator<long long int>]'
  706 |       operator=(vector&& __x) noexcept(_Alloc_traits::_S_nothrow_move())
      |       ^~~~~~~~
/usr/include/c++/9/bits/stl_vector.h:706:26: note:   no known conversion for argument 1 from 'std::vector<int>' to 'std::vector<long long int>&&'
  706 |       operator=(vector&& __x) noexcept(_Alloc_traits::_S_nothrow_move())
      |                 ~~~~~~~~~^~~
/usr/include/c++/9/bits/stl_vector.h:727:7: note: candidate: 'std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(std::initializer_list<_Tp>) [with _Tp = long long int; _Alloc = std::allocator<long long int>]'
  727 |       operator=(initializer_list<value_type> __l)
      |       ^~~~~~~~
/usr/include/c++/9/bits/stl_vector.h:727:46: note:   no known conversion for argument 1 from 'std::vector<int>' to 'std::initializer_list<long long int>'
  727 |       operator=(initializer_list<value_type> __l)
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~