結果
問題 |
No.402 最も海から遠い場所
|
ユーザー |
![]() |
提出日時 | 2016-05-22 18:50:50 |
言語 | Java (openjdk 23) |
結果 |
MLE
|
実行時間 | - |
コード長 | 1,314 bytes |
コンパイル時間 | 2,310 ms |
コンパイル使用メモリ | 77,872 KB |
実行使用メモリ | 656,952 KB |
最終ジャッジ日時 | 2024-11-06 10:07:56 |
合計ジャッジ時間 | 15,425 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 16 MLE * 1 -- * 2 |
ソースコード
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); } }