結果

問題 No.1638 Robot Maze
ユーザー tenten
提出日時 2021-08-10 08:43:57
言語 Java
(openjdk 23)
結果
AC  
実行時間 104 ms / 2,000 ms
コード長 3,034 bytes
コンパイル時間 2,269 ms
コンパイル使用メモリ 79,348 KB
実行使用メモリ 51,888 KB
最終ジャッジ日時 2024-09-22 09:31:55
合計ジャッジ時間 8,028 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 49
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws Exception {
Scanner sc = new Scanner();
int h = sc.nextInt();
int w = sc.nextInt();
int u = sc.nextInt();
int d = sc.nextInt();
int r = sc.nextInt();
int l = sc.nextInt();
long k = sc.nextLong();
int p = sc.nextInt();
int sx = sc.nextInt() - 1;
int sy = sc.nextInt() - 1;
int tx = sc.nextInt() - 1;
int ty = sc.nextInt() - 1;
char[][] field = new char[h][];
for (int i = 0; i < h; i++) {
field[i] = sc.next().toCharArray();
}
PriorityQueue<Path> queue = new PriorityQueue<>();
queue.add(new Path(sx, sy, 0));
long[][] costs = new long[h][w];
for (long[] arr : costs) {
Arrays.fill(arr, Long.MAX_VALUE);
}
while (queue.size() > 0) {
Path pt = queue.poll();
if (field[pt.r][pt.c] == '@') {
pt.value += p;
}
if (costs[pt.r][pt.c] <= pt.value) {
continue;
}
costs[pt.r][pt.c] = pt.value;
if (pt.r > 0 && field[pt.r - 1][pt.c] != '#') {
queue.add(new Path(pt.r - 1, pt.c, pt.value + u));
}
if (pt.r < h - 1 && field[pt.r + 1][pt.c] != '#') {
queue.add(new Path(pt.r + 1, pt.c, pt.value + d));
}
if (pt.c > 0 && field[pt.r][pt.c - 1] != '#') {
queue.add(new Path(pt.r, pt.c - 1, pt.value + l));
}
if (pt.c < w - 1 && field[pt.r][pt.c + 1] != '#') {
queue.add(new Path(pt.r, pt.c + 1, pt.value + r));
}
}
if (costs[tx][ty] <= k) {
System.out.println("Yes");
} else {
System.out.println("No");
}
}
static class Path implements Comparable<Path> {
int r;
int c;
long value;
public Path(int r, int c, long value) {
this.r = r;
this.c = c;
this.value = value;
}
public int compareTo(Path another) {
if (value == another.value) {
return 0;
} else if (value < another.value) {
return -1;
} else {
return 1;
}
}
}
}
class Scanner {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer("");
public Scanner() throws Exception {
}
public int nextInt() throws Exception {
return Integer.parseInt(next());
}
public long nextLong() throws Exception {
return Long.parseLong(next());
}
public String next() throws Exception {
if (!st.hasMoreTokens()) {
st = new StringTokenizer(br.readLine());
}
return st.nextToken();
}
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0