結果

問題 No.971 いたずらっ子
ユーザー htensai
提出日時 2020-03-25 14:06:34
言語 Java
(openjdk 23)
結果
AC  
実行時間 590 ms / 2,000 ms
コード長 879 bytes
コンパイル時間 2,479 ms
コンパイル使用メモリ 77,544 KB
実行使用メモリ 74,228 KB
最終ジャッジ日時 2024-11-07 11:43:11
合計ジャッジ時間 11,297 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        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 + 1][w + 1];
        Arrays.fill(costs[0], Integer.MAX_VALUE / 10);
        for (int i = 2; i <= h; i++) {
            costs[i][0] = Integer.MAX_VALUE / 10;
        }
        for (int i = 1; i <= h; i++) {
            for (int j = 1; j <= w; j++) {
                costs[i][j] = Math.min(costs[i - 1][j], costs[i][j - 1]) + 1;
                if (field[i - 1][j - 1] == 'k') {
                    costs[i][j] += i + j - 2;
                }
            }
        }
        System.out.println(costs[h][w] - 1);
    }
}
0