結果

問題 No.971 いたずらっ子
ユーザー tentententen
提出日時 2020-08-25 11:49:45
言語 Java19
(openjdk 21)
結果
AC  
実行時間 500 ms / 2,000 ms
コード長 930 bytes
コンパイル時間 2,024 ms
コンパイル使用メモリ 73,688 KB
実行使用メモリ 113,724 KB
最終ジャッジ日時 2023-08-07 08:08:52
合計ジャッジ時間 10,163 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 500 ms
112,432 KB
testcase_01 AC 500 ms
113,724 KB
testcase_02 AC 475 ms
88,872 KB
testcase_03 AC 476 ms
113,472 KB
testcase_04 AC 470 ms
112,892 KB
testcase_05 AC 474 ms
113,180 KB
testcase_06 AC 443 ms
91,772 KB
testcase_07 AC 152 ms
56,796 KB
testcase_08 AC 401 ms
68,504 KB
testcase_09 AC 374 ms
68,900 KB
testcase_10 AC 149 ms
56,444 KB
testcase_11 AC 117 ms
56,164 KB
testcase_12 AC 117 ms
56,328 KB
testcase_13 AC 125 ms
55,636 KB
testcase_14 AC 171 ms
56,448 KB
testcase_15 AC 126 ms
55,968 KB
testcase_16 AC 130 ms
55,440 KB
testcase_17 AC 119 ms
55,452 KB
testcase_18 AC 118 ms
55,752 KB
testcase_19 AC 119 ms
55,684 KB
testcase_20 AC 119 ms
55,716 KB
testcase_21 AC 124 ms
56,344 KB
testcase_22 AC 124 ms
56,488 KB
testcase_23 AC 119 ms
55,920 KB
testcase_24 AC 119 ms
56,204 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    static final int MOD = 1000000007;
    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][];
        long[][] counts = new long[h + 1][w + 1];
        Arrays.fill(counts[0], Long.MAX_VALUE / 10);
        for (int i = 0; i < h; i++) {
            field[i] = sc.next().toCharArray();
            counts[i + 1][0] = Long.MAX_VALUE / 10;
        }
        counts[0][1] = -1;
        counts[1][0] = -1;
        for (int i = 1; i <= h; i++) {
            for (int j = 1; j <= w; j++) {
                counts[i][j] = Math.min(counts[i - 1][j], counts[i][j - 1]) + 1;
                if (field[i - 1][j - 1] == 'k') {
                    counts[i][j] += i - 1 + j - 1;
                }
            }
        }
        System.out.println(counts[h][w]);
    }
}
0