結果

問題 No.1638 Robot Maze
ユーザー ks2mks2m
提出日時 2021-08-06 21:41:20
言語 Java21
(openjdk 21)
結果
AC  
実行時間 87 ms / 2,000 ms
コード長 2,010 bytes
コンパイル時間 2,894 ms
コンパイル使用メモリ 77,884 KB
実行使用メモリ 54,912 KB
最終ジャッジ日時 2023-10-17 02:58:21
合計ジャッジ時間 7,256 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 52 ms
53,616 KB
testcase_01 AC 51 ms
53,604 KB
testcase_02 AC 52 ms
52,652 KB
testcase_03 AC 73 ms
54,460 KB
testcase_04 AC 52 ms
53,608 KB
testcase_05 AC 52 ms
53,612 KB
testcase_06 AC 52 ms
53,604 KB
testcase_07 AC 52 ms
52,648 KB
testcase_08 AC 51 ms
52,528 KB
testcase_09 AC 52 ms
53,604 KB
testcase_10 AC 51 ms
53,616 KB
testcase_11 AC 52 ms
53,612 KB
testcase_12 AC 51 ms
53,612 KB
testcase_13 AC 52 ms
53,608 KB
testcase_14 AC 76 ms
54,168 KB
testcase_15 AC 65 ms
54,180 KB
testcase_16 AC 59 ms
53,748 KB
testcase_17 AC 59 ms
53,624 KB
testcase_18 AC 53 ms
52,652 KB
testcase_19 AC 59 ms
53,760 KB
testcase_20 AC 66 ms
53,764 KB
testcase_21 AC 57 ms
53,652 KB
testcase_22 AC 56 ms
53,624 KB
testcase_23 AC 57 ms
52,528 KB
testcase_24 AC 59 ms
53,616 KB
testcase_25 AC 58 ms
53,616 KB
testcase_26 AC 58 ms
53,748 KB
testcase_27 AC 57 ms
52,628 KB
testcase_28 AC 57 ms
53,568 KB
testcase_29 AC 59 ms
52,692 KB
testcase_30 AC 52 ms
53,612 KB
testcase_31 AC 52 ms
51,568 KB
testcase_32 AC 72 ms
54,168 KB
testcase_33 AC 84 ms
54,556 KB
testcase_34 AC 79 ms
54,452 KB
testcase_35 AC 87 ms
54,580 KB
testcase_36 AC 75 ms
54,468 KB
testcase_37 AC 79 ms
54,772 KB
testcase_38 AC 77 ms
54,308 KB
testcase_39 AC 84 ms
54,912 KB
testcase_40 AC 83 ms
54,904 KB
testcase_41 AC 79 ms
54,456 KB
testcase_42 AC 85 ms
54,460 KB
testcase_43 AC 74 ms
54,472 KB
testcase_44 AC 85 ms
54,588 KB
testcase_45 AC 78 ms
54,472 KB
testcase_46 AC 84 ms
54,464 KB
testcase_47 AC 73 ms
54,896 KB
testcase_48 AC 75 ms
54,464 KB
testcase_49 AC 80 ms
54,528 KB
testcase_50 AC 74 ms
54,600 KB
testcase_51 AC 84 ms
54,412 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.PriorityQueue;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] sa = br.readLine().split(" ");
		int h = Integer.parseInt(sa[0]);
		int w = Integer.parseInt(sa[1]);

		sa = br.readLine().split(" ");
		int[] cos = new int[4];
		for (int i = 0; i < 4; i++) {
			cos[i] = Integer.parseInt(sa[i]);
		}
		long k = Long.parseLong(sa[4]);
		int p = Integer.parseInt(sa[5]);

		sa = br.readLine().split(" ");
		int xs = Integer.parseInt(sa[0]) - 1;
		int ys = Integer.parseInt(sa[1]) - 1;
		int xt = Integer.parseInt(sa[2]) - 1;
		int yt = Integer.parseInt(sa[3]) - 1;

		char[][] c = new char[h][w];
		for (int i = 0; i < h; i++) {
			c[i] = br.readLine().toCharArray();
		}
		br.close();

		int[] dx = {-1, 1, 0, 0};
		int[] dy = {0, 0, 1, -1};

		int s = xs * w + ys;
		long[] d = new long[h * w];
		Arrays.fill(d, Long.MAX_VALUE);
		d[s] = 0;
		PriorityQueue<Node> que = new PriorityQueue<Node>();
		Node first = new Node(s, 0);
		que.add(first);

		while (!que.isEmpty()) {
			Node cur = que.poll();
			if (cur.d > d[cur.v]) {
				continue;
			}
			int cx = cur.v / w;
			int cy = cur.v % w;
			for (int i = 0; i < 4; i++) {
				int nx = cx + dx[i];
				int ny = cy + dy[i];
				if (nx < 0 || h <= nx || ny < 0 || w <= ny || c[nx][ny] == '#') {
					continue;
				}
				int next = nx * w + ny;
				long alt = d[cur.v] + cos[i];
				if (c[nx][ny] == '@') {
					alt += p;
				}
				if (alt < d[next]) {
					d[next] = alt;
					que.add(new Node(next, alt));
				}
			}
		}
		if (d[xt * w + yt] <= k) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}

	static class Node implements Comparable<Node> {
		int v;
		long d;

		public Node(int v, long d) {
			this.v = v;
			this.d = d;
		}

		public int compareTo(Node o) {
			return Long.compare(d, o.d);
		}
	}
}
0