제출 #1358437

#제출 시각아이디문제언어결과실행 시간메모리
1358437orgiloogiiCyberland (APIO23_cyberland)C++20
컴파일 에러
0 ms0 KiB
#include "cyberland.h"
#include <bits/stdc++.h>
#include <vector>
using namespace std;
vector <vector <array <double, 2>>> adj;
vector <vector <double>> dp;
const double inf = 1e18;
double solve(int n, int m, int k, int h, vector<int> x, vector<int> y, vector<int> c, vector<int> arr) {
    k = min(k, 70);
    vis.assign(n + 1, vector <bool>(k, 0));
    adj.assign(n + 1, {});
    dp.assign(n + 1, vector <double> (k + 1, inf));
    for (int i = 0;i < m;i++) {
        adj[x[i]].push_back({y[i], c[i]});
        adj[y[i]].push_back({x[i], c[i]});
    }
    vector <int> zer;
    zer.push_back(0);
    vector <bool> vis(n + 1, 0);
    queue <int> q;
    q.push(0);
    vis[0] = true;
    while (!q.empty()) {
        auto u = q.front();
        q.pop();
        for (auto [v, _] : adj[u]) {
            if (vis[v]) continue;
            if (v == h) {
                vis[h] = true;
                continue;
            }
            vis[v] = true;
            if (arr[v] == 0) {
                zer.push_back(v);
            }
            q.push(v);
        }
    }
    if (!vis[h]) return -1.0;
    priority_queue <pair <double, pair <int, int>>, vector <pair <double, pair <int, int>>>, greater <pair <double, pair <int, int>>>> pq; 
    for (auto x : zer) {
        for (int i = 0;i <= k;i++) {
            dp[x][i] = 0;
        }
        pq.push({0.0, {x, 0}});
    }
    while (!pq.empty()) {
        auto curr = pq.top().ff;
        auto x = pq.top().ss.ff;
        auto y = pq.top().ss.ss;
        pq.pop();
        if (dp[x][y] < curr || x == h) continue;
        for (auto [v, w] : adj[x]) {
            if (arr[v] == 0) continue;
            if (dp[v][y] > curr + w) {
                dp[v][y] = curr + w;
                pq.push({curr + w, v, y});
            } 
            if (arr[v] == 2 && y < k && dp[v][y + 1] > (curr + w) / 2) {
                dp[v][y + 1] = (curr + w) / 2;
                pq.push({(curr + w) / 2, {v, y + 1}});
            }
        }
    }
    // for (int i = 0;i <= k;i++) {
    //     cout << dp[h][i] << ' ';
    // }
    return -1.0;
}

컴파일 시 표준 에러 (stderr) 메시지

cyberland.cpp: In function 'double solve(int, int, int, int, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
cyberland.cpp:10:5: error: 'vis' was not declared in this scope
   10 |     vis.assign(n + 1, vector <bool>(k, 0));
      |     ^~~
cyberland.cpp:14:28: warning: narrowing conversion of 'y.std::vector<int>::operator[](((std::vector<int>::size_type)i))' from '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} to 'double' [-Wnarrowing]
   14 |         adj[x[i]].push_back({y[i], c[i]});
      |         ~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~
cyberland.cpp:14:28: warning: narrowing conversion of 'c.std::vector<int>::operator[](((std::vector<int>::size_type)i))' from '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} to 'double' [-Wnarrowing]
cyberland.cpp:15:28: warning: narrowing conversion of 'x.std::vector<int>::operator[](((std::vector<int>::size_type)i))' from '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} to 'double' [-Wnarrowing]
   15 |         adj[y[i]].push_back({x[i], c[i]});
      |         ~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~
cyberland.cpp:15:28: warning: narrowing conversion of 'c.std::vector<int>::operator[](((std::vector<int>::size_type)i))' from '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} to 'double' [-Wnarrowing]
cyberland.cpp:48:30: error: 'const __gnu_cxx::__alloc_traits<std::allocator<std::pair<double, std::pair<int, int> > >, std::pair<double, std::pair<int, int> > >::value_type' {aka 'const struct std::pair<double, std::pair<int, int> >'} has no member named 'ff'
   48 |         auto curr = pq.top().ff;
      |                              ^~
cyberland.cpp:49:27: error: 'const __gnu_cxx::__alloc_traits<std::allocator<std::pair<double, std::pair<int, int> > >, std::pair<double, std::pair<int, int> > >::value_type' {aka 'const struct std::pair<double, std::pair<int, int> >'} has no member named 'ss'
   49 |         auto x = pq.top().ss.ff;
      |                           ^~
cyberland.cpp:50:27: error: 'const __gnu_cxx::__alloc_traits<std::allocator<std::pair<double, std::pair<int, int> > >, std::pair<double, std::pair<int, int> > >::value_type' {aka 'const struct std::pair<double, std::pair<int, int> >'} has no member named 'ss'
   50 |         auto y = pq.top().ss.ss;
      |                           ^~
cyberland.cpp:57:24: error: no matching function for call to 'std::priority_queue<std::pair<double, std::pair<int, int> >, std::vector<std::pair<double, std::pair<int, int> > >, std::greater<std::pair<double, std::pair<int, int> > > >::push(<brace-enclosed initializer list>)'
   57 |                 pq.push({curr + w, v, y});
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/13/queue:66,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:157,
                 from cyberland.cpp:2:
/usr/include/c++/13/bits/stl_queue.h:738:7: note: candidate: 'void std::priority_queue<_Tp, _Sequence, _Compare>::push(const value_type&) [with _Tp = std::pair<double, std::pair<int, int> >; _Sequence = std::vector<std::pair<double, std::pair<int, int> > >; _Compare = std::greater<std::pair<double, std::pair<int, int> > >; value_type = std::pair<double, std::pair<int, int> >]'
  738 |       push(const value_type& __x)
      |       ^~~~
/usr/include/c++/13/bits/stl_queue.h:738:30: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const std::priority_queue<std::pair<double, std::pair<int, int> >, std::vector<std::pair<double, std::pair<int, int> > >, std::greater<std::pair<double, std::pair<int, int> > > >::value_type&' {aka 'const std::pair<double, std::pair<int, int> >&'}
  738 |       push(const value_type& __x)
      |            ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/13/bits/stl_queue.h:746:7: note: candidate: 'void std::priority_queue<_Tp, _Sequence, _Compare>::push(value_type&&) [with _Tp = std::pair<double, std::pair<int, int> >; _Sequence = std::vector<std::pair<double, std::pair<int, int> > >; _Compare = std::greater<std::pair<double, std::pair<int, int> > >; value_type = std::pair<double, std::pair<int, int> >]'
  746 |       push(value_type&& __x)
      |       ^~~~
/usr/include/c++/13/bits/stl_queue.h:746:25: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::priority_queue<std::pair<double, std::pair<int, int> >, std::vector<std::pair<double, std::pair<int, int> > >, std::greater<std::pair<double, std::pair<int, int> > > >::value_type&&' {aka 'std::pair<double, std::pair<int, int> >&&'}
  746 |       push(value_type&& __x)
      |            ~~~~~~~~~~~~~^~~
cyberland.cpp:61:24: error: no matching function for call to 'std::priority_queue<std::pair<double, std::pair<int, int> >, std::vector<std::pair<double, std::pair<int, int> > >, std::greater<std::pair<double, std::pair<int, int> > > >::push(<brace-enclosed initializer list>)'
   61 |                 pq.push({(curr + w) / 2, {v, y + 1}});
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/13/bits/stl_queue.h:738:7: note: candidate: 'void std::priority_queue<_Tp, _Sequence, _Compare>::push(const value_type&) [with _Tp = std::pair<double, std::pair<int, int> >; _Sequence = std::vector<std::pair<double, std::pair<int, int> > >; _Compare = std::greater<std::pair<double, std::pair<int, int> > >; value_type = std::pair<double, std::pair<int, int> >]'
  738 |       push(const value_type& __x)
      |       ^~~~
/usr/include/c++/13/bits/stl_queue.h:738:30: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const std::priority_queue<std::pair<double, std::pair<int, int> >, std::vector<std::pair<double, std::pair<int, int> > >, std::greater<std::pair<double, std::pair<int, int> > > >::value_type&' {aka 'const std::pair<double, std::pair<int, int> >&'}
  738 |       push(const value_type& __x)
      |            ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/13/bits/stl_queue.h:746:7: note: candidate: 'void std::priority_queue<_Tp, _Sequence, _Compare>::push(value_type&&) [with _Tp = std::pair<double, std::pair<int, int> >; _Sequence = std::vector<std::pair<double, std::pair<int, int> > >; _Compare = std::greater<std::pair<double, std::pair<int, int> > >; value_type = std::pair<double, std::pair<int, int> >]'
  746 |       push(value_type&& __x)
      |       ^~~~
/usr/include/c++/13/bits/stl_queue.h:746:25: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::priority_queue<std::pair<double, std::pair<int, int> >, std::vector<std::pair<double, std::pair<int, int> > >, std::greater<std::pair<double, std::pair<int, int> > > >::value_type&&' {aka 'std::pair<double, std::pair<int, int> >&&'}
  746 |       push(value_type&& __x)
      |            ~~~~~~~~~~~~~^~~