結果

問題 No.402 最も海から遠い場所
ユーザー uafr_csuafr_cs
提出日時 2016-07-22 23:07:31
言語 Java19
(openjdk 21)
結果
AC  
実行時間 944 ms / 3,000 ms
コード長 1,322 bytes
コンパイル時間 2,245 ms
コンパイル使用メモリ 75,000 KB
実行使用メモリ 112,580 KB
最終ジャッジ日時 2023-08-06 10:00:35
合計ジャッジ時間 11,150 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 125 ms
55,620 KB
testcase_01 AC 127 ms
55,752 KB
testcase_02 AC 138 ms
55,700 KB
testcase_03 AC 126 ms
55,412 KB
testcase_04 AC 125 ms
55,728 KB
testcase_05 AC 126 ms
55,552 KB
testcase_06 AC 126 ms
56,140 KB
testcase_07 AC 127 ms
55,416 KB
testcase_08 AC 127 ms
55,968 KB
testcase_09 AC 129 ms
55,604 KB
testcase_10 AC 128 ms
55,640 KB
testcase_11 AC 129 ms
56,024 KB
testcase_12 AC 127 ms
55,584 KB
testcase_13 AC 185 ms
56,132 KB
testcase_14 AC 166 ms
56,856 KB
testcase_15 AC 285 ms
59,396 KB
testcase_16 AC 347 ms
60,012 KB
testcase_17 AC 655 ms
84,872 KB
testcase_18 AC 928 ms
112,424 KB
testcase_19 AC 944 ms
111,776 KB
testcase_20 AC 929 ms
112,212 KB
testcase_21 AC 932 ms
112,580 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Arrays;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Scanner;
import java.util.Set;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		final int H = sc.nextInt();
		final int W = sc.nextInt();
		
		boolean[][] is_block = new boolean[H + 2][W + 2];
		for(int i = 0; i < H; i++){
			final char[] input = sc.next().toCharArray();
			
			for(int j = 0; j < W; j++){
				is_block[i + 1][j + 1] = input[j] == '#';
			}
		}
		
		final int INF = Integer.MAX_VALUE / 2;
		int[][] DP = new int[H + 2][W + 2];
		for(int i = 0; i < DP.length; i++){
			for(int j = 0; j < DP[i].length; j++){
				DP[i][j] = is_block[i][j] ? INF : 0;
			}
		}
		
		for(int i = 1; i <= H; i++){
			for(int j = 1; j <= W; j++){
				DP[i][j] = Math.min(DP[i][j], Math.min(Math.min(DP[i - 1][j], DP[i][j - 1]), Math.min(DP[i - 1][j - 1], DP[i - 1][j + 1])) + 1);
			}
		}
		
		for(int i = H; i >= 1; i--){
			for(int j = W; j >= 1; j--){
				DP[i][j] = Math.min(DP[i][j], Math.min(Math.min(DP[i + 1][j], DP[i][j + 1]), Math.min(DP[i + 1][j + 1], DP[i + 1][j - 1])) + 1);
			}
		}
		
		int max = 0;
		for(int i = 0; i < DP.length; i++){
			for(int j = 0; j < DP[i].length; j++){
				max = Math.max(max, DP[i][j]);
			}
		}
		
		System.out.println(max);
	}
}
0