Submission #941985

#TimeUsernameProblemLanguageResultExecution timeMemory
941985beabossAncient Books (IOI17_books)C++14
Compilation error
0 ms0 KiB
// Source: https://oj.uz/problem/view/IOI17_books // #include "books.h" #include "bits/stdc++.h" using namespace std; #define s second #define f first #define pb push_back typedef long long ll; typedef pair<ll, ll> pii; typedef vector<pii> vpii; typedef vector<ll> vi; #define FOR(i, a, b) for (ll i = (a); i<b; i++) bool ckmin(ll& a, ll b){ return b < a ? a = b, true : false; } bool ckmax(ll& a, ll b){ return b > a ? a = b, true : false; } const ll N = 1e6 + 10; ll ri[N], le[N]; bool vis[N]; vi nxt; ll n; ll l,r ; void extend() { ll ll = nxt[l]; while (ll < l && l > 0) { l--; ll = min(ll, nxt[l]); } ll rr = nxt[r]; while (r < rr && r < n-1) { r++; rr = max(rr, nxt[r]); } } ll minimum_walk(vector<int> p, ll s) { n = p.size(); l = r = s; nxt = p; ll ans = 0; FOR(i, 0, n) ans += abs(i - p[i]); ll st = 0; for (;st < n;st++) if (p[st] != st) break; ll en = n-1; for (;en >= 0;en--) if (p[en] != en) break; if (st >= en) return 0; while (l > st || r < en) { extend(); // cout << l << r << endl; ll lo = l; ll ro = r; ll cr = 0; while (l == lo && r < en) { cr+=2;r++; // cout << 'd' << endl; extend(); } bool rw = (nxt[r] < l); ll fl = l, fr=r; l = lo;r = ro; ll cl = 0; while (r == ro && l > st) { // cout << l << endl; cl+=2;l--;extend(); } // cout << 'd' << endl; bool lw = (nxt[l] > r); l = min(l, fl); r = max(r, fr); // assert(lw ^ rw); if (!lw || !rw) { ans += cl + cr; break; } ans += min(cl, cr); } return ans; } // int main() { // ios::sync_with_stdio(false); // cin.tie(nullptr); // // FOR(i, 0, 8) { // // mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); // // ll n = 100; // // vi here(n); // // FOR(i, 0, n) here[i] = i; // // shuffle(here.begin(), here.end(), rng); // // FOR(i, 0, n) cout << here[i] << ' '; // // cout << endl; // ll res = minimum_walk({0, 2, 4, 5, 1, 6, 3}, 0); // cout << res << endl; // }

Compilation message (stderr)

books.cpp: In function 'void extend()':
books.cpp:40:4: error: expected ';' before 'rr'
   40 |  ll rr = nxt[r];
      |    ^~~
      |    ;
books.cpp:40:2: warning: statement has no effect [-Wunused-value]
   40 |  ll rr = nxt[r];
      |  ^~
books.cpp:41:13: error: 'rr' was not declared in this scope; did you mean 'r'?
   41 |  while (r < rr && r < n-1) {
      |             ^~
      |             r
books.cpp: In function 'll minimum_walk(std::vector<int>, ll)':
books.cpp:50:8: error: no match for 'operator=' (operand types are 'vi' {aka 'std::vector<long long int>'} and 'std::vector<int>')
   50 |  nxt = p;
      |        ^
In file included from /usr/include/c++/10/vector:72,
                 from books.h:1,
                 from books.cpp:3:
/usr/include/c++/10/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++/10/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++/10/vector:67,
                 from books.h:1,
                 from books.cpp:3:
/usr/include/c++/10/bits/stl_vector.h:709: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>]'
  709 |       operator=(vector&& __x) noexcept(_Alloc_traits::_S_nothrow_move())
      |       ^~~~~~~~
/usr/include/c++/10/bits/stl_vector.h:709:26: note:   no known conversion for argument 1 from 'std::vector<int>' to 'std::vector<long long int>&&'
  709 |       operator=(vector&& __x) noexcept(_Alloc_traits::_S_nothrow_move())
      |                 ~~~~~~~~~^~~
/usr/include/c++/10/bits/stl_vector.h:730: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>]'
  730 |       operator=(initializer_list<value_type> __l)
      |       ^~~~~~~~
/usr/include/c++/10/bits/stl_vector.h:730:46: note:   no known conversion for argument 1 from 'std::vector<int>' to 'std::initializer_list<long long int>'
  730 |       operator=(initializer_list<value_type> __l)
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~