結果
問題 | No.1638 Robot Maze |
ユーザー | tenten |
提出日時 | 2021-08-10 08:43:57 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 106 ms / 2,000 ms |
コード長 | 3,034 bytes |
コンパイル時間 | 2,631 ms |
コンパイル使用メモリ | 79,156 KB |
実行使用メモリ | 55,360 KB |
最終ジャッジ日時 | 2023-10-22 08:33:17 |
合計ジャッジ時間 | 9,886 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 57 ms
53,700 KB |
testcase_01 | AC | 55 ms
53,688 KB |
testcase_02 | AC | 56 ms
53,684 KB |
testcase_03 | AC | 91 ms
55,048 KB |
testcase_04 | AC | 61 ms
53,688 KB |
testcase_05 | AC | 58 ms
53,020 KB |
testcase_06 | AC | 58 ms
53,700 KB |
testcase_07 | AC | 58 ms
53,684 KB |
testcase_08 | AC | 57 ms
53,696 KB |
testcase_09 | AC | 56 ms
53,684 KB |
testcase_10 | AC | 57 ms
53,688 KB |
testcase_11 | AC | 58 ms
53,708 KB |
testcase_12 | AC | 58 ms
53,696 KB |
testcase_13 | AC | 57 ms
53,700 KB |
testcase_14 | AC | 89 ms
54,976 KB |
testcase_15 | AC | 87 ms
54,536 KB |
testcase_16 | AC | 77 ms
54,560 KB |
testcase_17 | AC | 87 ms
54,496 KB |
testcase_18 | AC | 62 ms
53,712 KB |
testcase_19 | AC | 89 ms
54,912 KB |
testcase_20 | AC | 86 ms
54,544 KB |
testcase_21 | AC | 81 ms
54,252 KB |
testcase_22 | AC | 81 ms
54,256 KB |
testcase_23 | AC | 80 ms
53,744 KB |
testcase_24 | AC | 80 ms
53,696 KB |
testcase_25 | AC | 80 ms
54,264 KB |
testcase_26 | AC | 82 ms
53,736 KB |
testcase_27 | AC | 83 ms
54,268 KB |
testcase_28 | AC | 83 ms
53,752 KB |
testcase_29 | AC | 72 ms
53,700 KB |
testcase_30 | AC | 56 ms
53,684 KB |
testcase_31 | AC | 57 ms
53,700 KB |
testcase_32 | AC | 87 ms
54,536 KB |
testcase_33 | AC | 100 ms
54,524 KB |
testcase_34 | AC | 103 ms
54,924 KB |
testcase_35 | AC | 86 ms
54,512 KB |
testcase_36 | AC | 95 ms
54,844 KB |
testcase_37 | AC | 93 ms
54,480 KB |
testcase_38 | AC | 93 ms
54,876 KB |
testcase_39 | AC | 104 ms
55,312 KB |
testcase_40 | AC | 97 ms
55,004 KB |
testcase_41 | AC | 98 ms
54,496 KB |
testcase_42 | AC | 100 ms
54,524 KB |
testcase_43 | AC | 102 ms
54,884 KB |
testcase_44 | AC | 102 ms
55,236 KB |
testcase_45 | AC | 104 ms
54,820 KB |
testcase_46 | AC | 100 ms
54,972 KB |
testcase_47 | AC | 95 ms
54,928 KB |
testcase_48 | AC | 105 ms
54,820 KB |
testcase_49 | AC | 96 ms
55,016 KB |
testcase_50 | AC | 97 ms
54,868 KB |
testcase_51 | AC | 106 ms
55,360 KB |
ソースコード
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(); } }