結果
問題 | No.1638 Robot Maze |
ユーザー | tenten |
提出日時 | 2021-08-10 08:43:57 |
言語 | Java21 (openjdk 21) |
結果 |
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 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 55 ms
50,384 KB |
testcase_01 | AC | 55 ms
50,320 KB |
testcase_02 | AC | 54 ms
50,072 KB |
testcase_03 | AC | 99 ms
51,368 KB |
testcase_04 | AC | 54 ms
50,080 KB |
testcase_05 | AC | 53 ms
50,524 KB |
testcase_06 | AC | 55 ms
50,252 KB |
testcase_07 | AC | 54 ms
50,024 KB |
testcase_08 | AC | 55 ms
50,436 KB |
testcase_09 | AC | 54 ms
50,204 KB |
testcase_10 | AC | 54 ms
50,140 KB |
testcase_11 | AC | 54 ms
50,520 KB |
testcase_12 | AC | 55 ms
50,572 KB |
testcase_13 | AC | 54 ms
50,432 KB |
testcase_14 | AC | 82 ms
51,612 KB |
testcase_15 | AC | 83 ms
51,312 KB |
testcase_16 | AC | 74 ms
51,556 KB |
testcase_17 | AC | 83 ms
51,424 KB |
testcase_18 | AC | 58 ms
50,408 KB |
testcase_19 | AC | 83 ms
51,496 KB |
testcase_20 | AC | 85 ms
51,520 KB |
testcase_21 | AC | 69 ms
50,596 KB |
testcase_22 | AC | 78 ms
51,008 KB |
testcase_23 | AC | 66 ms
50,628 KB |
testcase_24 | AC | 77 ms
50,956 KB |
testcase_25 | AC | 69 ms
50,884 KB |
testcase_26 | AC | 79 ms
51,040 KB |
testcase_27 | AC | 80 ms
50,792 KB |
testcase_28 | AC | 79 ms
50,768 KB |
testcase_29 | AC | 80 ms
51,000 KB |
testcase_30 | AC | 54 ms
50,424 KB |
testcase_31 | AC | 54 ms
50,556 KB |
testcase_32 | AC | 93 ms
51,432 KB |
testcase_33 | AC | 87 ms
51,684 KB |
testcase_34 | AC | 103 ms
51,652 KB |
testcase_35 | AC | 98 ms
51,600 KB |
testcase_36 | AC | 104 ms
51,676 KB |
testcase_37 | AC | 94 ms
51,696 KB |
testcase_38 | AC | 96 ms
51,556 KB |
testcase_39 | AC | 100 ms
51,416 KB |
testcase_40 | AC | 87 ms
51,728 KB |
testcase_41 | AC | 100 ms
51,852 KB |
testcase_42 | AC | 99 ms
51,684 KB |
testcase_43 | AC | 103 ms
51,724 KB |
testcase_44 | AC | 99 ms
51,888 KB |
testcase_45 | AC | 99 ms
51,448 KB |
testcase_46 | AC | 102 ms
51,784 KB |
testcase_47 | AC | 99 ms
51,624 KB |
testcase_48 | AC | 103 ms
51,696 KB |
testcase_49 | AC | 93 ms
51,620 KB |
testcase_50 | AC | 101 ms
51,616 KB |
testcase_51 | AC | 99 ms
51,720 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(); } }