結果
問題 | No.971 いたずらっ子 |
ユーザー | tenten |
提出日時 | 2022-08-30 10:31:22 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 1,978 ms / 2,000 ms |
コード長 | 2,257 bytes |
コンパイル時間 | 2,714 ms |
コンパイル使用メモリ | 78,764 KB |
実行使用メモリ | 83,244 KB |
最終ジャッジ日時 | 2024-04-25 02:19:50 |
合計ジャッジ時間 | 18,243 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1,978 ms
83,152 KB |
testcase_01 | AC | 1,935 ms
83,244 KB |
testcase_02 | AC | 1,522 ms
68,588 KB |
testcase_03 | AC | 1,560 ms
81,840 KB |
testcase_04 | AC | 1,417 ms
79,904 KB |
testcase_05 | AC | 1,497 ms
82,156 KB |
testcase_06 | AC | 1,194 ms
73,424 KB |
testcase_07 | AC | 100 ms
40,648 KB |
testcase_08 | AC | 536 ms
51,908 KB |
testcase_09 | AC | 515 ms
51,956 KB |
testcase_10 | AC | 104 ms
40,448 KB |
testcase_11 | AC | 45 ms
37,176 KB |
testcase_12 | AC | 46 ms
37,244 KB |
testcase_13 | AC | 47 ms
37,152 KB |
testcase_14 | AC | 82 ms
38,704 KB |
testcase_15 | AC | 50 ms
36,924 KB |
testcase_16 | AC | 49 ms
36,920 KB |
testcase_17 | AC | 45 ms
36,980 KB |
testcase_18 | AC | 45 ms
37,312 KB |
testcase_19 | AC | 45 ms
37,060 KB |
testcase_20 | AC | 49 ms
36,920 KB |
testcase_21 | AC | 46 ms
37,272 KB |
testcase_22 | AC | 46 ms
37,116 KB |
testcase_23 | AC | 44 ms
36,800 KB |
testcase_24 | AC | 45 ms
37,116 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(); char[][] field = new char[h][]; for (int i = 0; i < h; i++) { field[i] = sc.next().toCharArray(); } int[][] costs = new int[h][w]; for (int[] arr : costs) { Arrays.fill(arr, Integer.MAX_VALUE); } PriorityQueue<Path> queue = new PriorityQueue<>(); queue.add(new Path(0, 0, 0)); while (queue.size() > 0) { Path p = queue.poll(); if (field[p.r][p.c] == 'k') { p.value += p.r + p.c; } if (costs[p.r][p.c] <= p.value) { continue; } costs[p.r][p.c] = p.value; if (p.r < h - 1) { queue.add(new Path(p.r + 1, p.c, p.value + 1)); } if (p.c < w - 1) { queue.add(new Path(p.r, p.c + 1, p.value + 1)); } } System.out.println(costs[h - 1][w - 1]); } static class Path implements Comparable<Path> { int r; int c; int value; public Path(int r, int c, int value) { this.r = r; this.c = c; this.value = value; } public int compareTo(Path another) { return value - another.value; } } } class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); StringBuilder sb = new StringBuilder(); public Scanner() throws Exception { } public int nextInt() throws Exception { return Integer.parseInt(next()); } public long nextLong() throws Exception { return Long.parseLong(next()); } public double nextDouble() throws Exception { return Double.parseDouble(next()); } public String next() throws Exception { while (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }