結果

問題 No.1283 Extra Fee
ユーザー KoDKoD
提出日時 2020-11-06 22:01:14
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 3,492 bytes
コンパイル時間 691 ms
コンパイル使用メモリ 77,240 KB
最終ジャッジ日時 2023-08-10 05:58:32
合計ジャッジ時間 1,614 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
main.cpp: 関数 ‘int main()’ 内:
main.cpp:57:16: エラー: ‘const std::tuple<long unsigned int, long unsigned int, long unsigned int, long unsigned int> <structured bindings>’ has incomplete type
   57 |   constexpr range(std::size_t first, std::size_t last) noexcept: first(first), last(std::max(first, last)) { }
      |                ^~~~~~~~~~~~
次のファイルから読み込み:  /usr/local/gcc7/include/c++/12.2.0/vector:64,
         次から読み込み:  main.cpp:10:
/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<long unsigned int, long unsigned int, long unsigned int, long unsigned int>; _Alloc = std::allocator<std::tuple<long unsigned int, long unsigned int, long unsigned int, long unsigned 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<long unsigned int, long unsigned int, long unsigned int, long unsigned int> >; _Requires = void; _Tp = std::tuple<long unsigned int, long unsigned int, long unsigned int, long unsigned int>; _Sequence = std::vector<std::tuple<long unsigned int, long unsigned int, long unsigned int, long unsigned int> >; _Compare = std::greater<std::tuple<long unsigned int, long unsigned int, long unsigned int, long unsigned int> >]’
main.cpp:49:71:   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<long unsigned int, long unsigned int, long unsigned int, long unsigned 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/string

ソースコード

diff #

#line 1 "main.cpp"

/**
 * @title Template
 */

#include <iostream>
#include <algorithm>
#include <utility>
#include <numeric>
#include <vector>
#include <array>
#include <cassert>
#include <queue>

#line 2 "/Users/kodamankod/Desktop/cpp_programming/Library/other/chmin_chmax.cpp"

template <class T, class U>
constexpr bool chmin(T &lhs, const U &rhs) {
  if (lhs > rhs) { lhs = rhs; return true; }
  return false;
}

template <class T, class U>
constexpr bool chmax(T &lhs, const U &rhs) {
  if (lhs < rhs) { lhs = rhs; return true; }
  return false;
}

/**
 * @title Chmin/Chmax
 */
#line 2 "/Users/kodamankod/Desktop/cpp_programming/Library/other/range.cpp"

#line 4 "/Users/kodamankod/Desktop/cpp_programming/Library/other/range.cpp"

class range {
  struct iter {
    std::size_t itr;
    constexpr iter(std::size_t pos) noexcept: itr(pos) { }
    constexpr void operator ++ () noexcept { ++itr; }
    constexpr bool operator != (iter other) const noexcept { return itr != other.itr; }
    constexpr std::size_t operator * () const noexcept { return itr; }
  };

  struct reviter {
    std::size_t itr;
    constexpr reviter(std::size_t pos) noexcept: itr(pos) { }
    constexpr void operator ++ () noexcept { --itr; }
    constexpr bool operator != (reviter other) const noexcept { return itr != other.itr; }
    constexpr std::size_t operator * () const noexcept { return itr; }
  };

  const iter first, last;

public:
  constexpr range(std::size_t first, std::size_t last) noexcept: first(first), last(std::max(first, last)) { }
  constexpr iter begin() const noexcept { return first; }
  constexpr iter end() const noexcept { return last; }
  constexpr reviter rbegin() const noexcept { return reviter(*last - 1); } 
  constexpr reviter rend() const noexcept { return reviter(*first - 1); } 
};

/**
 * @title Range
 */
#line 17 "main.cpp"

using i32 = std::int32_t;
using i64 = std::int64_t;
using u32 = std::uint32_t;
using u64 = std::uint64_t;
using isize = std::ptrdiff_t;
using usize = std::size_t;

constexpr i32 inf32 = (i32(1) << 30) - 1;
constexpr i64 inf64 = (i64(1) << 62) - 1;

constexpr std::array<i32, 8> dx = { 0, 0, -1, 1, -1, -1, 1, 1 };
constexpr std::array<i32, 8> dy = { -1, 1, 0, 0, -1, 1, -1, 1 };

int main() {
  usize N, M;
  std::cin >> N >> M;
  std::vector<std::vector<u32>> cost(N, std::vector<u32>(N));
  while (M--) {
    usize x, y;
    u32 c;
    std::cin >> x >> y >> c;
    --x; --y;
    cost[x][y] = c;
  }
  std::vector<std::vector<std::array<u64, 2>>> dist(N, std::vector<std::array<u64, 2>>(N));
  for (auto &a: dist) {
    for (auto &b: a) {
      b.fill(inf64);
    }
  }
  using State = std::tuple<u64, usize, usize, usize>;
  std::priority_queue<State, std::vector<State>, std::greater<State>> que;
  const auto try_push = [&](const usize x, const usize y, const usize k, const u64 d) {
    if (chmin(dist[x][y][k], d)) {
      que.emplace(dist[x][y][k], x, y, k);
    }
  };
  try_push(0, 0, 0, 0);
  while (!que.empty()) {
    const auto [d, x, y, k] = que.top();
    que.pop();
    if (d > dist[x][y][k]) {
      continue;
    }
    for (auto l: range(0, 4)) {
      const isize ni = (isize) x + dx[l];
      const isize nj = (isize) y + dy[l];
      if (ni >= 0 && ni < (isize) N && nj >= 0 && nj < (isize) N) {
        if (k == 0) {
          try_push(ni, nj, 1, dist[x][y][k] + 1);
        }
        try_push(ni, nj, k, dist[x][y][k] + cost[ni][nj] + 1);
      }
    }
  }
  std::cout << dist[N - 1][N - 1][1] << '\n';
  return 0;
}
0