結果
| 問題 |
No.971 いたずらっ子
|
| コンテスト | |
| ユーザー |
tenten
|
| 提出日時 | 2020-08-25 11:49:45 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 551 ms / 2,000 ms |
| コード長 | 930 bytes |
| コンパイル時間 | 2,737 ms |
| コンパイル使用メモリ | 77,440 KB |
| 実行使用メモリ | 99,280 KB |
| 最終ジャッジ日時 | 2024-11-07 11:46:47 |
| 合計ジャッジ時間 | 10,962 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 21 |
ソースコード
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]);
}
}
tenten