結果

問題 No.971 いたずらっ子
ユーザー htensaihtensai
提出日時 2020-03-25 14:06:34
言語 Java21
(openjdk 21)
結果
AC  
実行時間 497 ms / 2,000 ms
コード長 879 bytes
コンパイル時間 1,935 ms
コンパイル使用メモリ 74,484 KB
実行使用メモリ 86,044 KB
最終ジャッジ日時 2023-08-07 08:05:33
合計ジャッジ時間 10,325 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 497 ms
84,952 KB
testcase_01 AC 496 ms
85,220 KB
testcase_02 AC 491 ms
80,568 KB
testcase_03 AC 484 ms
86,044 KB
testcase_04 AC 473 ms
79,860 KB
testcase_05 AC 479 ms
85,104 KB
testcase_06 AC 450 ms
80,836 KB
testcase_07 AC 155 ms
56,168 KB
testcase_08 AC 443 ms
63,804 KB
testcase_09 AC 381 ms
64,236 KB
testcase_10 AC 152 ms
56,344 KB
testcase_11 AC 120 ms
55,656 KB
testcase_12 AC 119 ms
56,068 KB
testcase_13 AC 132 ms
55,600 KB
testcase_14 AC 175 ms
56,108 KB
testcase_15 AC 128 ms
55,852 KB
testcase_16 AC 134 ms
56,092 KB
testcase_17 AC 121 ms
56,008 KB
testcase_18 AC 120 ms
57,684 KB
testcase_19 AC 120 ms
55,760 KB
testcase_20 AC 124 ms
55,812 KB
testcase_21 AC 127 ms
55,364 KB
testcase_22 AC 123 ms
55,816 KB
testcase_23 AC 117 ms
55,940 KB
testcase_24 AC 119 ms
56,292 KB
権限があれば一括ダウンロードができます

ソースコード

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