Submission #980725

# Submission time Handle Problem Language Result Execution time Memory
980725 2024-05-12T10:56:42 Z vjudge1 Rainforest Jumps (APIO21_jumps) C++17
Compilation error
0 ms 0 KB
#include "jumps.h"
#include<bits/stdc++.h>
#define sz size()
#define ll long long
using namespace std;
const ll INF = 1e9;
const ll NN = 300300;

ll up[NN][21], dw[NN][21];
int n, ok = 1;
vector<vector<ll>> v;
vector<ll> h;
void init(int N, vector<int> H)
{
    n = N;
    h = H;
    v.resize(n);
    vector<ll> q;
    for(ll i = 0; i < n; ++i)
        up[i][0] = -1,
                   dw[i][0] = -1;
    for(ll i = 0; i < n; ++i)
    {
        ok &= h[i] == i + 1;
        while(q.sz && h[q.back()] < h[i])
            v[q.back()].push_back(i),
            up[q.back()][0] = i,
                              q.pop_back();
        q.push_back(i);
    }
    q.clear();
    for(ll i = n - 1; i >= 0; --i)
    {
        while(q.sz && h[q.back()] < h[i])
            v[q.back()].push_back(i),
            dw[q.back()][0] = i,
                              q.pop_back();
        q.push_back(i);
    }
    for(ll i = 0; i < n; ++i)
        if(dw[i][0] > up[i][0]) swap(up[i][0], dw[i][0]);
    for(ll i = 0; i < n; ++i)
        if(dw[i][0] < 0) swap(up[i][0], dw[i][0]);
    for(ll j = 1; j < 21; ++j)
        for(ll i = 0; i < n; ++i)
        {
            up[i][j] = up[up[i][j - 1]][j - 1];
            dw[i][j] = dw[dw[i][j - 1]][j - 1];
        }
}

int minimum_jumps(int a, int b, int c, int d)
{
    if(ok) return c - b;
    if(a == b && c == d)
    {
        ll ans = 0;
        for(ll j = 20; j >= 0; --j)
        {
            if(up[a][j] < 0) continue;
            if(h[up[a][j]] <= h[d])
                a = up[a][j], ans += (1 << j);
        }
        for(ll j = 20; j >= 0; --j)
        {
            if(dw[a][j] < 0) continue;
            if(h[dw[a][j]] <= h[d])
                a = dw[a][j], ans += (1 << j);
        }
        return a == d ? ans : -1;
    }
    vector<ll> dist(n, INF);
    queue<ll> q;
    for(ll i = a; i <= b; ++i)
    {
        dist[i] = 0;
        q.push(i);
    }
    while(q.sz)
    {
        ll s = q.front();
        q.pop();
        for(ll t : v[s])
        {
            if(dist[t] < INF) continue;
            dist[t] = dist[s] + 1;
            q.push(t);
        }
    }
    ll ans = INF;
    for(ll i = c; i <= d; ++i)
        ans = min(ans, dist[i]);
    return ans < INF ? ans : -1;
}

//signed main()
//{
//    ios_base::sync_with_stdio(0);
//    cin.tie(0), cout.tie(0);
//}

Compilation message

jumps.cpp: In function 'void init(int, std::vector<int>)':
jumps.cpp:16:9: error: no match for 'operator=' (operand types are 'std::vector<long long int>' and 'std::vector<int>')
   16 |     h = H;
      |         ^
In file included from /usr/include/c++/10/vector:72,
                 from jumps.h:1,
                 from jumps.cpp:1:
/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 jumps.h:1,
                 from jumps.cpp:1:
/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)
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~