結果

問題 No.402 最も海から遠い場所
ユーザー AreTrashAreTrash
提出日時 2016-05-22 18:50:50
言語 Java21
(openjdk 21)
結果
MLE  
実行時間 -
コード長 1,314 bytes
コンパイル時間 2,085 ms
コンパイル使用メモリ 77,740 KB
実行使用メモリ 646,928 KB
最終ジャッジ日時 2024-04-24 03:19:47
合計ジャッジ時間 14,109 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 112 ms
46,656 KB
testcase_01 AC 118 ms
41,244 KB
testcase_02 AC 132 ms
41,452 KB
testcase_03 AC 122 ms
41,284 KB
testcase_04 AC 108 ms
39,856 KB
testcase_05 AC 119 ms
41,300 KB
testcase_06 AC 116 ms
41,004 KB
testcase_07 AC 118 ms
41,396 KB
testcase_08 AC 117 ms
41,316 KB
testcase_09 AC 120 ms
41,272 KB
testcase_10 AC 124 ms
41,084 KB
testcase_11 AC 129 ms
41,320 KB
testcase_12 AC 123 ms
41,104 KB
testcase_13 AC 193 ms
43,620 KB
testcase_14 AC 166 ms
42,524 KB
testcase_15 AC 359 ms
54,336 KB
testcase_16 AC 473 ms
59,568 KB
testcase_17 AC 1,710 ms
260,764 KB
testcase_18 AC 2,251 ms
186,676 KB
testcase_19 MLE -
testcase_20 -- -
testcase_21 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;
import java.util.Queue;
import java.util.ArrayDeque;

class Yuki2_4{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		int H = sc.nextInt();
		int W = sc.nextInt();
		int map[][] = new int[H + 4][W + 4];
		Queue<Integer> que = new ArrayDeque<Integer>();
		
		for(int i = 2; i <= H + 1; i++){
		String input = sc.next();
			for(int j = 2; j <= W + 1; j++){
				if(input.charAt(j - 2) == '#'){
					map[i][j] = 1510;
				}else{
					que.add(0);
					que.add(j);
					que.add(i);
				}
			}
		}
		
		for(int i = 2; i <= H + 1; i++){
			que.add(0);
			que.add(1);
			que.add(i);
			que.add(0);
			que.add(W + 2);
			que.add(i);
		}
		for(int i = 2; i <= W + 1; i++){
			que.add(0);
			que.add(i);
			que.add(1);
			que.add(0);
			que.add(i);
			que.add(H + 2);
        }
		
		int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
		int dy[] = {1, 0, -1, 0, 1, -1, 1, -1};
		int max = 0;
		
		while(!que.isEmpty()){
			int distance = que.poll();
			int x = que.poll();
			int y = que.poll();
			for(int i = 0; i < 8; i++){
				int nx = x + dx[i];
				int ny = y + dy[i];
				if(map[ny][nx] > distance + 1){
					max = Math.max(max, map[ny][nx] = distance + 1);
					que.add(distance + 1);
					que.add(nx);
					que.add(ny);
				}
			}
		}
		
		System.out.println(max);
	}
}
0