結果

問題 No.1638 Robot Maze
ユーザー 👑 NachiaNachia
提出日時 2021-08-06 21:57:27
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 6 ms / 2,000 ms
コード長 1,440 bytes
コンパイル時間 1,116 ms
コンパイル使用メモリ 87,852 KB
実行使用メモリ 4,556 KB
最終ジャッジ日時 2023-10-17 03:20:07
合計ジャッジ時間 2,478 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,468 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,468 KB
testcase_15 AC 4 ms
4,464 KB
testcase_16 AC 4 ms
4,464 KB
testcase_17 AC 4 ms
4,464 KB
testcase_18 AC 4 ms
4,464 KB
testcase_19 AC 4 ms
4,464 KB
testcase_20 AC 4 ms
4,464 KB
testcase_21 AC 4 ms
4,464 KB
testcase_22 AC 4 ms
4,464 KB
testcase_23 AC 4 ms
4,464 KB
testcase_24 AC 4 ms
4,464 KB
testcase_25 AC 4 ms
4,464 KB
testcase_26 AC 4 ms
4,464 KB
testcase_27 AC 4 ms
4,464 KB
testcase_28 AC 4 ms
4,464 KB
testcase_29 AC 4 ms
4,464 KB
testcase_30 AC 2 ms
4,348 KB
testcase_31 AC 2 ms
4,348 KB
testcase_32 AC 5 ms
4,472 KB
testcase_33 AC 5 ms
4,536 KB
testcase_34 AC 5 ms
4,472 KB
testcase_35 AC 5 ms
4,556 KB
testcase_36 AC 5 ms
4,472 KB
testcase_37 AC 5 ms
4,472 KB
testcase_38 AC 5 ms
4,468 KB
testcase_39 AC 5 ms
4,472 KB
testcase_40 AC 5 ms
4,520 KB
testcase_41 AC 5 ms
4,536 KB
testcase_42 AC 5 ms
4,532 KB
testcase_43 AC 6 ms
4,520 KB
testcase_44 AC 5 ms
4,472 KB
testcase_45 AC 5 ms
4,472 KB
testcase_46 AC 5 ms
4,472 KB
testcase_47 AC 5 ms
4,468 KB
testcase_48 AC 6 ms
4,472 KB
testcase_49 AC 5 ms
4,472 KB
testcase_50 AC 5 ms
4,520 KB
testcase_51 AC 6 ms
4,468 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <utility>
#include <queue>
using namespace std;
using i32 = int32_t;
using i64 = int64_t;
#define rep(i,n) for(int i=0; i<(n); i++)

const i64 INF = 1001001001001001;

struct Edge{ int to; i64 d; };

int H,W;
i64 X[6];
int sy,sx,ty,tx;
string G;
vector<vector<Edge>> E;
vector<i64> D;

int main(){
  cin >> H >> W;
  rep(t,6) cin >> X[t];
  cin >> sy >> sx >> ty >> tx; sy--; sx--; ty--; tx--;
  rep(y,H){
    string g; cin >> g;
    G += g;
  }

  E.resize(H*W);

  rep(y,H) rep(x,W){
    int p = y * W + x;
    if(y != 0){
      E[p].push_back({p-W,X[0]});
      E[p-W].push_back({p,X[1]});
    }
    if(x != 0){
      E[p].push_back({p-1,X[3]});
      E[p-1].push_back({p,X[2]});
    }
  }
  rep(p,H*W){
    for(auto& e : E[p]){
      if(G[e.to] == '#') e.d = INF;
      if(G[e.to] == '@') e.d += X[5];
    }
  }

  D.assign(H*W,INF);

  priority_queue<pair<i64,int>> G;
  G.push({0,sy*W+sx});
  D[sy*W+sx] = 0;
  while(G.size()){
    int p = G.top().second;
    i64 d = -G.top().first;
    G.pop();
    if(D[p] != d) continue;
    for(auto e : E[p]){
      i64 nxd = e.d + d;
      if(nxd >= D[e.to]) continue;
      D[e.to] = nxd;
      G.push({-nxd,e.to});
    }
  }

  if(D[ty*W+tx] <= X[4]) cout << "Yes\n";
  else cout << "No\n";
  return 0;
}




struct ios_do_not_sync{
  ios_do_not_sync(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
  }
} ios_do_not_sync_instance;




0