Submission #883504

#TimeUsernameProblemLanguageResultExecution timeMemory
883504SalihSahinJakarta Skyscrapers (APIO15_skyscraper)C++14
Compilation error
0 ms0 KiB
#include<bits/stdc++.h>
#define pb push_back
#define int long long
#define mp make_pair
 
using namespace std;
const int inf = 1e18;
const int mod = 1e9 + 7;
const int N = 2e3 + 5;

vector<vector<int> >  dis(N, vector<int>(N, inf));

int32_t main(){
    ios_base::sync_with_stdio(false), cin.tie();
    int n, m;
    cin>>n>>m;
    int start = 0, finish = 0;
    for(int i = 0; i < m; i++){
        int b, p;
        cin>>b>>p;
        if(i == 0) start = b;
        if(i == 1) finish = b;

        for(int k = b%p; k < n; k += p){
            dis[b][k] = min(dis[b][k], abs(b - k)/p);
        }
    }
    vector<pair<int, int> > adj[N];
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            if(i == j || dis[i][j] == inf) continue;
            adj[i].pb(mp(j, dis[i][j]));
        }
    }

    priority_queue<pair<int, int> > pq;
    vector<int> best(N, inf), vis(N);
    best[start] = 0;
    pq.push(mp(0, start));
    
    while(pq.size()){
        int node = pq.top().second;
        int len = pq.top().first * (-1);
        pq.pop();
        
        if(vis[node]) continue;
        vis[node] = 1;

        for(auto itr: adj[node]){
            if(best[itr.first] > best[node] + itr.second){
                pq.push(mp(-(best[node] + itr.second), itr.first));
                best[itr].first = best[node] + itr.second;
            }
        }
    }

    if(best[finish] == inf) cout<<-1<<endl;
    else cout<<best[finish]<<endl;
    return 0;
}

Compilation message (stderr)

skyscraper.cpp: In function 'int32_t main()':
skyscraper.cpp:52:21: error: no match for 'operator[]' (operand types are 'std::vector<long long int>' and 'std::pair<long long int, long long int>')
   52 |                 best[itr].first = best[node] + itr.second;
      |                     ^
In file included from /usr/include/c++/10/vector:67,
                 from /usr/include/c++/10/queue:61,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:86,
                 from skyscraper.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 = long long int; _Alloc = std::allocator<long long int>; std::vector<_Tp, _Alloc>::reference = long long 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 'std::pair<long long int, long long int>' to 'std::vector<long long 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 = long long int; _Alloc = std::allocator<long long int>; std::vector<_Tp, _Alloc>::const_reference = const long long 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 'std::pair<long long int, long long int>' to 'std::vector<long long int>::size_type' {aka 'long unsigned int'}
 1061 |       operator[](size_type __n) const _GLIBCXX_NOEXCEPT
      |                  ~~~~~~~~~~^~~
skyscraper.cpp:43:13: warning: unused variable 'len' [-Wunused-variable]
   43 |         int len = pq.top().first * (-1);
      |             ^~~