結果

問題 No.971 いたずらっ子
ユーザー htensaihtensai
提出日時 2020-03-25 14:06:34
言語 Java21
(openjdk 21)
結果
AC  
実行時間 520 ms / 2,000 ms
コード長 879 bytes
コンパイル時間 2,009 ms
コンパイル使用メモリ 78,132 KB
実行使用メモリ 74,480 KB
最終ジャッジ日時 2024-04-25 02:12:03
合計ジャッジ時間 9,670 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 498 ms
74,480 KB
testcase_01 AC 520 ms
74,380 KB
testcase_02 AC 507 ms
68,412 KB
testcase_03 AC 440 ms
73,204 KB
testcase_04 AC 494 ms
66,184 KB
testcase_05 AC 513 ms
74,144 KB
testcase_06 AC 405 ms
68,680 KB
testcase_07 AC 150 ms
41,832 KB
testcase_08 AC 448 ms
52,984 KB
testcase_09 AC 352 ms
53,144 KB
testcase_10 AC 145 ms
41,512 KB
testcase_11 AC 115 ms
41,000 KB
testcase_12 AC 111 ms
41,216 KB
testcase_13 AC 118 ms
41,116 KB
testcase_14 AC 148 ms
42,924 KB
testcase_15 AC 123 ms
41,040 KB
testcase_16 AC 130 ms
41,408 KB
testcase_17 AC 114 ms
41,308 KB
testcase_18 AC 99 ms
40,108 KB
testcase_19 AC 111 ms
41,172 KB
testcase_20 AC 111 ms
41,460 KB
testcase_21 AC 103 ms
40,612 KB
testcase_22 AC 109 ms
41,088 KB
testcase_23 AC 103 ms
40,216 KB
testcase_24 AC 112 ms
41,368 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