結果

問題 No.1638 Robot Maze
ユーザー tnakao0123tnakao0123
提出日時 2021-08-07 18:50:33
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 4 ms / 2,000 ms
コード長 1,870 bytes
コンパイル時間 894 ms
コンパイル使用メモリ 100,972 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-18 23:38:53
合計ジャッジ時間 2,470 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 3 ms
4,348 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 1 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 3 ms
4,348 KB
testcase_15 AC 2 ms
4,348 KB
testcase_16 AC 3 ms
4,348 KB
testcase_17 AC 2 ms
4,348 KB
testcase_18 AC 2 ms
4,348 KB
testcase_19 AC 2 ms
4,348 KB
testcase_20 AC 3 ms
4,348 KB
testcase_21 AC 3 ms
4,348 KB
testcase_22 AC 2 ms
4,348 KB
testcase_23 AC 3 ms
4,348 KB
testcase_24 AC 2 ms
4,348 KB
testcase_25 AC 2 ms
4,348 KB
testcase_26 AC 2 ms
4,348 KB
testcase_27 AC 2 ms
4,348 KB
testcase_28 AC 2 ms
4,348 KB
testcase_29 AC 2 ms
4,348 KB
testcase_30 AC 2 ms
4,348 KB
testcase_31 AC 2 ms
4,348 KB
testcase_32 AC 2 ms
4,348 KB
testcase_33 AC 3 ms
4,348 KB
testcase_34 AC 3 ms
4,348 KB
testcase_35 AC 3 ms
4,348 KB
testcase_36 AC 2 ms
4,348 KB
testcase_37 AC 2 ms
4,348 KB
testcase_38 AC 2 ms
4,348 KB
testcase_39 AC 3 ms
4,348 KB
testcase_40 AC 2 ms
4,348 KB
testcase_41 AC 3 ms
4,348 KB
testcase_42 AC 2 ms
4,348 KB
testcase_43 AC 4 ms
4,348 KB
testcase_44 AC 3 ms
4,348 KB
testcase_45 AC 2 ms
4,348 KB
testcase_46 AC 2 ms
4,348 KB
testcase_47 AC 2 ms
4,348 KB
testcase_48 AC 3 ms
4,348 KB
testcase_49 AC 3 ms
4,348 KB
testcase_50 AC 3 ms
4,348 KB
testcase_51 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 1638.cc:  No.1638 Robot Maze - yukicoder
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_H = 100;
const int MAX_W = 100;
const int MAX_N = MAX_H * MAX_W;
const long long LINF = 1LL << 62;
const int dys[] = { -1, 1, 0, 0 }, dxs[] = { 0, 0, 1, -1 };

enum { DU, DD, DR, DL };

/* typedef */

typedef long long ll;
typedef pair<ll,int> pli;

/* global variables */

char fs[MAX_H][MAX_W + 4];
ll ds[MAX_N];

/* subroutines */

inline int yx2p(int y, int x, int w) { return y * w + x; }
inline void p2yx(int p, int &y, int &x, int w) { y = p / w, x = p % w; }

/* main */

int main() {
  int h, w, dcs[4], p, sy, sx, gy, gx;
  ll k;
  scanf("%d%d%d%d%d%d%lld%d%d%d%d%d",
	&h, &w, dcs + DU, dcs + DD, dcs + DR, dcs + DL, &k, &p,
	&sy, &sx, &gy, &gx);
  sy--, sx--, gy--, gx--;
  int st = yx2p(sy, sx, w), gl = yx2p(gy, gx, w);

  for (int y = 0; y < h; y++) scanf("%s", fs[y]);

  fill(ds, ds + h * w, LINF);
  ds[st] = 0;

  priority_queue<pli> q;
  q.push(pli(0, st));

  while (! q.empty()) {
    pli u = q.top(); q.pop();
    ll ud = -u.first;
    int up = u.second;
    if (up == gl) break;

    int uy, ux;
    p2yx(up, uy, ux, w);

    for (int di = 0; di < 4; di++) {
      int vy = uy + dys[di], vx = ux + dxs[di];
      if (vy >= 0 && vy < h && vx >= 0 && vx < w && fs[vy][vx] != '#') {
	int vp = yx2p(vy, vx, w);
	ll vd = ud + dcs[di] + (fs[vy][vx] == '@' ? p : 0);
	if (ds[vp] > vd) {
	  ds[vp] = vd;
	  q.push(pli(-vd, vp));
	}
      }
    }
  }

  if (ds[gl] <= k) puts("Yes");
  else puts("No");
  return 0;
}
0