結果

問題 No.1449 新プロランド
ユーザー MisterMister
提出日時 2021-03-31 15:56:17
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 2,275 bytes
コンパイル時間 643 ms
コンパイル使用メモリ 75,968 KB
最終ジャッジ日時 2023-08-25 16:49:38
合計ジャッジ時間 999 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
main.cpp: 関数 ‘void solve()’ 内:
main.cpp:34:14: エラー: ‘std::tuple<int, int, int> <structured bindings>’ has incomplete type
   34 | using MinHeap = std::priority_queue<T, std::vector<T>, std::greater<T>>;
      |              ^~~~~~~~~
次のファイルから読み込み:  /usr/local/gcc7/include/c++/12.2.0/vector:64,
         次から読み込み:  /Users/tiramister/CompetitiveProgramming/Cpp/CppLibrary/Graph/graph.hpp:3:
/usr/local/gcc7/include/c++/12.2.0/bits/stl_vector.h: In instantiation of ‘std::_Vector_base<_Tp, _Alloc>::~_Vector_base() [with _Tp = std::tuple<int, int, int>; _Alloc = std::allocator<std::tuple<int, int, int> >]’:
/usr/local/gcc7/include/c++/12.2.0/bits/stl_vector.h:526:7:   required from ‘std::priority_queue<_Tp, _Sequence, _Compare>::priority_queue() [with _Seq = std::vector<std::tuple<int, int, int>, std::allocator<std::tuple<int, int, int> > >; _Requires = void; _Tp = std::tuple<int, int, int>; _Sequence = std::vector<std::tuple<int, int, int>, std::allocator<std::tuple<int, int, int> > >; _Compare = std::greater<std::tuple<int, int, int> >]’
main.cpp:27:35:   required from here
/usr/local/gcc7/include/c++/12.2.0/bits/stl_vector.h:367:49: エラー: invalid use of incomplete type ‘class std::tuple<int, int, int>’
  367 |                       _M_impl._M_end_of_storage - _M_impl._M_start);
      |                       ~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~
次のファイルから読み込み:  /usr/local/gcc7/include/c++/12.2.0/bits/stl_algobase.h:64,
         次から読み込み:  /usr/local/gcc7/include/c++/12.2.0/vector:60:
/usr/local/gcc7/include/c++/12.2.0/bits/stl_pair.h:90:11: 備考: declaration of ‘class std::tuple<int, int, int>’
   90 |     class tuple;
      |           ^~~~~
次のファイルから読み込み:  /usr/local/gcc7/include/c++/12.2.0/bits/stl_pair.h:60:
/usr/local/gcc7/include/c++/12.2.0/type_traits: In substitution of ‘template<class _Tp, class ... _Args> using __is_

ソースコード

diff #

#line 2 "/Users/tiramister/CompetitiveProgramming/Cpp/CppLibrary/Graph/graph.hpp"

#include <vector>

template <class Cost = int>
struct Edge {
    int src, dst;
    Cost cost;

    Edge() = default;
    Edge(int src, int dst, Cost cost = 1)
        : src(src), dst(dst), cost(cost){};

    bool operator<(const Edge<Cost>& e) const { return cost < e.cost; }
    bool operator>(const Edge<Cost>& e) const { return cost > e.cost; }
};

template <class Cost = int>
struct Graph : public std::vector<std::vector<Edge<Cost>>> {
    using std::vector<std::vector<Edge<Cost>>>::vector;

    void span(bool direct, int src, int dst, Cost cost = 1) {
        (*this)[src].emplace_back(src, dst, cost);
        if (!direct) (*this)[dst].emplace_back(dst, src, cost);
    }
};
#line 2 "/Users/tiramister/CompetitiveProgramming/Cpp/CppLibrary/Tools/heap_alias.hpp"

#include <queue>

template <class T>
using MaxHeap = std::priority_queue<T>;
template <class T>
using MinHeap = std::priority_queue<T, std::vector<T>, std::greater<T>>;
#line 3 "main.cpp"
#include <iostream>
#include <algorithm>
#line 6 "main.cpp"

using namespace std;
constexpr int INF = 1 << 30;
constexpr int C = 1000;

void solve() {
    int n, m;
    cin >> n >> m;

    Graph<int> graph(n);
    while (m--) {
        int u, v, c;
        cin >> u >> v >> c;
        graph.span(false, --u, --v, c);
    }

    vector<int> ts(n);
    for (auto& t : ts) cin >> t;

    auto dp = vector(n, vector(C + 2, INF));
    // 食べた時間がCより大なら、移動時間は常に0なので区別不要
    MinHeap<tuple<int, int, int>> heap;
    // 時間, 頂点, おにぎり時間

    dp[0][ts[0]] = ts[0];
    heap.emplace(ts[0], 0, ts[0]);

    while (!heap.empty()) {
        auto [d, v, t] = heap.top();
        heap.pop();
        if (dp[v][t] < d) continue;

        for (auto e : graph[v]) {
            auto u = e.dst;
            auto nd = d + e.cost / t + ts[u];
            auto nt = min(C + 1, t + ts[u]);

            if (nd >= dp[u][nt]) continue;
            dp[u][nt] = nd;
            heap.emplace(nd, u, nt);
        }
    }

    cout << *min_element(dp[n - 1].begin(), dp[n - 1].end()) << "\n";
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    solve();

    return 0;
}
0