답안 #938776

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
938776 2024-03-05T14:19:27 Z vjudge1 Toll (BOI17_toll) C++17
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
#include <random>
#define int long long
using namespace std;
const int inf = 1e9;
void dfs(vector<int>& dp, vector<map<int,int>> graph, int cur)
{
    for (auto a : graph)
    {
        dp[a] = min(dp[a],dp[cur]+a.ss);
        dfs(dp,graph,a);
    }
}
signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int k,n,m,o;
    cin >> k >> n >> m >> o;
    if (k==1)
    {
        vector<int> edges(n-1,inf);
        for (int i = 0; i < m; i++)
        {
            int a,b,c;
            cin >> a >> b >> c;
            
            edges[a] = c;
            
        }
        vector<int> pref_sum(n-1,0);
        pref_sum[0] = edges[0];
        for (int i = 1; i < n-1; i++)
            pref_sum[i] = pref_sum[i-1]+edges[i];
            
        auto sum = [&](int l,int r)
        {
          return pref_sum[r] - (l > 0 ? pref_sum[l-1] : 0LL);  
        };
        
        for (int i = 0; i < o; i++)
        {
            int a,b;
            cin >> a >> b;
            if (sum(a,b-1) >= inf)
                cout << -1 << '\n';
            else
                cout << sum(a,b-1) << '\n';
        }
    }
    else 
    {
        //turk milleti meslin baban!!!!
        vector<map<int,int>> graph(n);
        for (int i = 0; i < m; i++)
        {
            int a,b,t;
            cin >> a >> b >> t;
            graph[a][b] = t;
        }
        vector<int> dp(n,inf);
        dp[0] = 0;
        dfs(dp,graph,0);
        for (int i = 0; i < o; i++)
        {
            int a,b;
            cin >> a >> b;
            if (dp[b] >= inf)
                cout << "-1\n";
            else
                cout << dp[b] << '\n';
        }
    }
    return 0;
}

Compilation message

toll.cpp: In function 'void dfs(std::vector<long long int>&, std::vector<std::map<long long int, long long int> >, long long int)':
toll.cpp:11:11: error: no match for 'operator[]' (operand types are 'std::vector<long long int>' and 'std::map<long long int, long long int>')
   11 |         dp[a] = min(dp[a],dp[cur]+a.ss);
      |           ^
In file included from /usr/include/c++/10/vector:67,
                 from /usr/include/c++/10/functional:62,
                 from /usr/include/c++/10/pstl/glue_algorithm_defs.h:13,
                 from /usr/include/c++/10/algorithm:74,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from toll.cpp:2:
/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::map<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::map<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
      |                  ~~~~~~~~~~^~~
toll.cpp:11:23: error: no match for 'operator[]' (operand types are 'std::vector<long long int>' and 'std::map<long long int, long long int>')
   11 |         dp[a] = min(dp[a],dp[cur]+a.ss);
      |                       ^
In file included from /usr/include/c++/10/vector:67,
                 from /usr/include/c++/10/functional:62,
                 from /usr/include/c++/10/pstl/glue_algorithm_defs.h:13,
                 from /usr/include/c++/10/algorithm:74,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from toll.cpp:2:
/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::map<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::map<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
      |                  ~~~~~~~~~~^~~
toll.cpp:11:37: error: 'class std::map<long long int, long long int>' has no member named 'ss'
   11 |         dp[a] = min(dp[a],dp[cur]+a.ss);
      |                                     ^~
toll.cpp:12:22: error: cannot convert 'std::map<long long int, long long int>' to 'long long int'
   12 |         dfs(dp,graph,a);
      |                      ^
      |                      |
      |                      std::map<long long int, long long int>
toll.cpp:7:59: note:   initializing argument 3 of 'void dfs(std::vector<long long int>&, std::vector<std::map<long long int, long long int> >, long long int)'
    7 | void dfs(vector<int>& dp, vector<map<int,int>> graph, int cur)
      |                                                           ^