結果
| 問題 |
No.971 いたずらっ子
|
| コンテスト | |
| ユーザー |
tenten
|
| 提出日時 | 2022-08-30 10:31:22 |
| 言語 | Java (openjdk 23) |
| 結果 |
TLE
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 2,257 bytes |
| コンパイル時間 | 2,363 ms |
| コンパイル使用メモリ | 78,520 KB |
| 実行使用メモリ | 83,008 KB |
| 最終ジャッジ日時 | 2024-11-07 11:51:53 |
| 合計ジャッジ時間 | 20,171 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 19 TLE * 2 |
ソースコード
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();
}
}
tenten