結果
問題 | No.1572 XI |
ユーザー | tenten |
提出日時 | 2021-06-29 12:11:51 |
言語 | Java21 (openjdk 21) |
結果 |
TLE
|
実行時間 | - |
コード長 | 3,913 bytes |
コンパイル時間 | 2,037 ms |
コンパイル使用メモリ | 79,012 KB |
実行使用メモリ | 128,508 KB |
最終ジャッジ日時 | 2024-06-25 17:29:47 |
合計ジャッジ時間 | 27,990 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 56 ms
42,264 KB |
testcase_01 | AC | 55 ms
37,168 KB |
testcase_02 | AC | 54 ms
37,268 KB |
testcase_03 | AC | 56 ms
37,152 KB |
testcase_04 | AC | 853 ms
59,820 KB |
testcase_05 | AC | 1,641 ms
82,020 KB |
testcase_06 | AC | 1,810 ms
100,228 KB |
testcase_07 | AC | 151 ms
46,048 KB |
testcase_08 | AC | 1,477 ms
82,528 KB |
testcase_09 | AC | 889 ms
61,840 KB |
testcase_10 | AC | 1,362 ms
69,464 KB |
testcase_11 | AC | 206 ms
47,332 KB |
testcase_12 | AC | 729 ms
55,096 KB |
testcase_13 | AC | 274 ms
48,356 KB |
testcase_14 | AC | 775 ms
55,092 KB |
testcase_15 | AC | 252 ms
47,960 KB |
testcase_16 | AC | 616 ms
54,272 KB |
testcase_17 | AC | 149 ms
44,832 KB |
testcase_18 | AC | 770 ms
60,232 KB |
testcase_19 | AC | 1,735 ms
84,048 KB |
testcase_20 | AC | 1,213 ms
67,480 KB |
testcase_21 | AC | 1,905 ms
102,396 KB |
testcase_22 | AC | 1,745 ms
80,708 KB |
testcase_23 | AC | 142 ms
44,056 KB |
testcase_24 | AC | 54 ms
37,152 KB |
testcase_25 | AC | 52 ms
36,916 KB |
testcase_26 | AC | 57 ms
37,276 KB |
testcase_27 | AC | 54 ms
37,284 KB |
testcase_28 | AC | 56 ms
37,312 KB |
testcase_29 | AC | 55 ms
37,308 KB |
testcase_30 | AC | 55 ms
37,136 KB |
testcase_31 | AC | 54 ms
36,920 KB |
testcase_32 | AC | 53 ms
37,308 KB |
testcase_33 | AC | 54 ms
37,444 KB |
testcase_34 | TLE | - |
testcase_35 | TLE | - |
testcase_36 | TLE | - |
testcase_37 | TLE | - |
testcase_38 | TLE | - |
testcase_39 | TLE | - |
testcase_40 | -- | - |
testcase_41 | -- | - |
testcase_42 | -- | - |
testcase_43 | -- | - |
testcase_44 | -- | - |
testcase_45 | -- | - |
testcase_46 | -- | - |
testcase_47 | -- | - |
testcase_48 | -- | - |
ソースコード
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 sr = sc.nextInt() - 1; int sx = sc.nextInt() - 1; int gr = sc.nextInt() - 1; int gc = sc.nextInt() - 1; char[][] field = new char[h][]; for (int i = 0; i < h; i++) { field[i] = sc.next().toCharArray(); } int[][][] costs = new int[h][w][6]; for (int[][] arr : costs) { for (int[] arr1 : arr) { Arrays.fill(arr1, Integer.MAX_VALUE); } } PriorityQueue<Path> queue = new PriorityQueue<>(); queue.add(new Path(sr, sx, 0, 0)); while (queue.size() > 0) { Path p = queue.poll(); if (field[p.r][p.c] == '#') { continue; } if (costs[p.r][p.c][p.idx] <= p.value) { continue; } costs[p.r][p.c][p.idx] = p.value; if (p.r > 0) { int nextIdx = p.idx; if (p.idx <= 2) { nextIdx++; } else if(p.idx == 3) { nextIdx = 0; } queue.add(new Path(p.r - 1, p.c, p.value + 1, nextIdx)); } if (p.r < h - 1) { int nextIdx = p.idx; if (p.idx == 0) { nextIdx = 3; } else if (p.idx <= 3) { nextIdx--; } queue.add(new Path(p.r + 1, p.c, p.value + 1, nextIdx)); } if (p.c > 0) { int nextIdx; if (p.idx == 0) { nextIdx = 4; } else if (p.idx == 4) { nextIdx = 2; } else if (p.idx == 2) { nextIdx = 5; } else if (p.idx == 5) { nextIdx = 0; } else { nextIdx = p.idx; } queue.add(new Path(p.r, p.c - 1, p.value + 1, nextIdx)); } if (p.c < w - 1) { int nextIdx; if (p.idx == 0) { nextIdx = 5; } else if (p.idx == 5) { nextIdx = 2; } else if (p.idx == 2) { nextIdx = 4; } else if (p.idx == 4) { nextIdx = 0; } else { nextIdx = p.idx; } queue.add(new Path(p.r, p.c + 1, p.value + 1, nextIdx)); } } if (costs[gr][gc][0] == Integer.MAX_VALUE) { System.out.println(-1); } else { System.out.println(costs[gr][gc][0]); } } static class Path implements Comparable<Path> { int r; int c; int value; int idx; public Path(int r, int c, int value, int idx) { this.r = r; this.c = c; this.value = value; this.idx = idx; } public int compareTo(Path another) { return value - another.value; } } } 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(); } }