結果

問題 No.20 砂漠のオアシス
ユーザー kyunakyuna
提出日時 2019-07-29 22:33:02
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 2,095 bytes
コンパイル時間 549 ms
コンパイル使用メモリ 74,480 KB
最終ジャッジ日時 2023-09-15 12:03:34
合計ジャッジ時間 982 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
main.cpp: 関数 ‘std::vector<_Tp> dijkstra(WeightedGraph<T>&, int)’ 内:
main.cpp:19:19: エラー: ‘numeric_limits’ was not declared in this scope
   19 |     const T INF = numeric_limits<T>::max();
      |                   ^~~~~~~~~~~~~~
main.cpp:19:35: エラー: expected primary-expression before ‘>’ token
   19 |     const T INF = numeric_limits<T>::max();
      |                                   ^
main.cpp:19:41: エラー: ‘max()’ の呼び出しに適合する関数がありません
   19 |     const T INF = numeric_limits<T>::max();
      |                                    ~~~~~^~
次のファイルから読み込み:  /usr/local/gcc7/include/c++/12.2.0/algorithm:60,
         次から読み込み:  main.cpp:1:
/usr/local/gcc7/include/c++/12.2.0/bits/stl_algobase.h:254:5: 備考: 候補: ‘template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)’
  254 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/local/gcc7/include/c++/12.2.0/bits/stl_algobase.h:254:5: 備考:   template argument deduction/substitution failed:
main.cpp:19:41: 備考:   候補では 2 個の引数が予期されますが、0 個の引数が与えられています
   19 |     const T INF = numeric_limits<T>::max();
      |                                    ~~~~~^~
/usr/local/gcc7/include/c++/12.2.0/bits/stl_algobase.h:300:5: 備考: 候補: ‘template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)’
  300 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/local/gcc7/include/c++/12.2.0/bits/stl_algobase.h:300:5: 備考:   template argument deduction/substitution failed:
main.cpp:19:41: 備考:   候補では 3 個の引数が予期されますが、0 個の引数が与えられています
   19 |     const T INF = numeric_limits<T>::max();
      |                                    ~~~~~^~
次のファイルから読み込み:  /usr/local/gcc7/include/c++/12

ソースコード

diff #

#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <tuple>
using namespace std;

template <typename T>
struct Edge { int src, dst; T cost;
    Edge(int dst, T cost) : src(-1), dst(dst), cost(cost) { }
    Edge(int src, int dst, T cost) : src(src), dst(dst), cost(cost) { }
};
template <typename T> using Edges = vector<Edge<T>>;
template <typename T> using WeightedGraph = vector<Edges<T>>;
template <typename T> using Matrix = vector<vector<T>>;

template <typename T>
vector<T> dijkstra(const WeightedGraph<T> &g, int s) {
    const T INF = numeric_limits<T>::max();
    vector<T> dist(g.size(), INF);
    vector<int> prev(g.size(), -1);
    using Pi = pair<T, int>;
    priority_queue<Pi, vector<Pi>, greater<Pi>> que;
    dist[s] = 0; que.emplace(dist[s], s);
    while (!que.empty()) {
        T cost; int u; tie(cost, u) = que.top(); que.pop();
        if (dist[u] < cost) continue;
        for (auto &e: g[u]) {
            int v = e.dst; T nc = e.cost;
            if (dist[v] <= dist[u] + nc) continue;
            dist[v] = dist[u] + nc; prev[v] = u;
            que.emplace(dist[v], v);
        }
    }
    return dist;
}

int main() {
    int n, v, oi, oj; cin >> n >> v >> oj >> oi; oi--, oj--;
    WeightedGraph<int> g(n * n);
    auto idx = [&](int i, int j) { return i * n + j; };
    auto out_field = [&](int i, int j) {
        return i < 0 || i >= n || j < 0 || j >= n;
    };
    int dij[] = {0, 1, 0, -1, 0};
    for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) {
        int cost; cin >> cost;
        for (int k = 0; k < 4; k++) {
            int ni = i + dij[k], nj = j + dij[k + 1];
            if (out_field(ni, nj)) continue;
            g[idx(ni, nj)].emplace_back(idx(i, j), cost);
        }
    }
    auto dist_s = dijkstra(g, idx(0, 0));
    bool ok = dist_s[idx(n - 1, n - 1)] < v;
    if (oi != -1 && oj != -1) {
        auto dist_o = dijkstra(g, idx(oi, oj));
        ok |= dist_o[idx(n - 1, n - 1)] < 2 * (v - dist_s[idx(oi, oj)]);
    }
    if (ok) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}
0