結果

問題 No.1638 Robot Maze
ユーザー hayatenhayaten
提出日時 2021-08-06 22:25:07
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 6 ms / 2,000 ms
コード長 2,760 bytes
コンパイル時間 5,286 ms
コンパイル使用メモリ 291,188 KB
実行使用メモリ 4,684 KB
最終ジャッジ日時 2023-10-17 03:49:06
合計ジャッジ時間 6,782 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 5 ms
4,684 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 4 ms
4,420 KB
testcase_15 AC 3 ms
4,348 KB
testcase_16 AC 4 ms
4,348 KB
testcase_17 AC 3 ms
4,348 KB
testcase_18 AC 3 ms
4,348 KB
testcase_19 AC 3 ms
4,348 KB
testcase_20 AC 3 ms
4,348 KB
testcase_21 AC 3 ms
4,348 KB
testcase_22 AC 3 ms
4,348 KB
testcase_23 AC 3 ms
4,348 KB
testcase_24 AC 3 ms
4,348 KB
testcase_25 AC 3 ms
4,348 KB
testcase_26 AC 3 ms
4,348 KB
testcase_27 AC 3 ms
4,348 KB
testcase_28 AC 3 ms
4,348 KB
testcase_29 AC 3 ms
4,348 KB
testcase_30 AC 2 ms
4,348 KB
testcase_31 AC 2 ms
4,348 KB
testcase_32 AC 5 ms
4,564 KB
testcase_33 AC 5 ms
4,420 KB
testcase_34 AC 5 ms
4,684 KB
testcase_35 AC 5 ms
4,420 KB
testcase_36 AC 5 ms
4,684 KB
testcase_37 AC 5 ms
4,568 KB
testcase_38 AC 5 ms
4,420 KB
testcase_39 AC 5 ms
4,684 KB
testcase_40 AC 5 ms
4,420 KB
testcase_41 AC 5 ms
4,420 KB
testcase_42 AC 5 ms
4,424 KB
testcase_43 AC 6 ms
4,420 KB
testcase_44 AC 6 ms
4,440 KB
testcase_45 AC 5 ms
4,420 KB
testcase_46 AC 6 ms
4,684 KB
testcase_47 AC 5 ms
4,420 KB
testcase_48 AC 5 ms
4,684 KB
testcase_49 AC 5 ms
4,420 KB
testcase_50 AC 5 ms
4,420 KB
testcase_51 AC 5 ms
4,684 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma region Macros
// #pragma GCC target("avx2")
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include <atcoder/all>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n - 1); i >= 0; i--)
#define ALL(v) v.begin(), v.end()
#define endl "\n"
#define popcount(bit) __builtin_popcount(bit)
#define popcountll(bit) __builtin_popcountll(bit)
#define pb push_back
#define eb emplace_back
using namespace std;
using namespace atcoder;
using P = pair<int, int>;
using PL = pair<long long, long long>;
using PP = pair<long long, P>;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int fx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int fy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll INF = (1LL <<62);

using Edge = pair <int, ll>;  // {行き先, 重み}
using Graph = vector<vector<Edge>>; // グラフ


vector<ll> dijkstra(const Graph &G, int s){
  vector<ll> dist((int)G.size(), INF);
  vector<vector<int>> prev((int)G.size()); // prev[v] := v から復元できる辺たち
  dist[s] = 0;
  priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<pair<ll, int>>> que;
  que.push(make_pair(0, s));
  while(!que.empty()) {
    auto cur = que.top(); que.pop();
    ll cur_dist = cur.first;
    int v = cur.second;
    if(cur_dist > dist[v]) continue; //枝狩り
    for(auto e : G[v]) {
      if(dist[e.first] > dist[v] + e.second){
        dist[e.first] = dist[v] + e.second;
        que.push(make_pair(dist[e.first], e.first));
      }
    }
  }
  return dist;
}


int main() {
  int h, w;
  cin >> h >> w;
  Graph G(h * w);
  ll u, d, r, l, k, p;
  cin >> u >> d >> r >> l >> k >> p;
  int sx, sy, gx, gy;
  cin >> sx >> sy >> gx >> gy;
  sx--, sy--, gx--, gy--;
  vector<string> grid(h);
  rep(i, h) cin >> grid[i];
  rep(i, h)rep(j, w){
    int start = i * w + j;
    int right = start + 1;
    int under = start + w;
    ll add2 = 0;
    if(grid[i][j] == '#')continue;
    if(j < w-1 && grid[i][j+1] != '#'){
      ll add1 = 0;
      ll add2 = 0;
      if(grid[i][j] == '@')add1 = p;
      if(grid[i][j+1] == '@')add2 = p;
      G[start].pb({right, r + add2});
      G[right].pb({start, add1 + l});
    }
    if(i < h-1 && grid[i+1][j] != '#'){
      ll add1 = 0;
      ll add2 = 0;
      if(grid[i][j] == '@')add1 = p;
      if(grid[i+1][j] == '@')add2 = p;
      G[start].pb({under, d + add2});
      G[under].pb({start, add1 + u});
    }
  }
  vector<ll> dist = dijkstra(G, sx * w + sy);
  if(dist[gx * w + gy] <= k){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}
0