結果
| 問題 |
No.402 最も海から遠い場所
|
| コンテスト | |
| ユーザー |
jp_ste
|
| 提出日時 | 2016-08-11 18:48:40 |
| 言語 | Java (openjdk 23) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 2,067 bytes |
| コンパイル時間 | 2,439 ms |
| コンパイル使用メモリ | 78,164 KB |
| 実行使用メモリ | 717,424 KB |
| 最終ジャッジ日時 | 2024-11-07 11:00:58 |
| 合計ジャッジ時間 | 14,595 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | RE * 3 |
| other | RE * 18 MLE * 1 |
ソースコード
import java.io.PrintWriter;
import java.util.LinkedList;
import java.util.Scanner;
public class Main {
static Scanner scan = new Scanner(System.in);
static PrintWriter out = new PrintWriter(System.out);
static int H, W;
static char[][] map;
static int [][] ansMap;
static int ans = 0;
public static void main(String[] args) {
H = scan.nextInt();
W = scan.nextInt();
LinkedList<Point> q = new LinkedList<>();
map = new char[H+2][W+2];
ansMap = new int[H+2][W+2];
for(int i=0; i<map.length; i++) {
String line = scan.nextLine();
for(int j=0; j<map[0].length; j++) {
if(i==0 || i==map.length-1 || j==0 || j==map[0].length-1) {
map[i][j] = '.';
q.add(new Point(j,i));
continue;
}
map[i][j] = line.charAt(j-1);
if(map[i][j] == '.') {
q.add(new Point(j,i));
}
}
}
int[] dx = {-1, 0, 1, -1, 1, -1, 0, 1};
int[] dy = {-1, -1, -1, 0, 0, 1, 1, 1};
while(!q.isEmpty()) {
Point now = q.poll();
for(int i=0; i<dx.length; i++) {
int nextX = now.x + dx[i];
int nextY = now.y + dy[i];
if(nextX >= 0 && nextX < map[0].length && nextY >= 0 && nextY < map.length) {
if(map[nextY][nextX] == '#' && ansMap[nextY][nextX] == 0) {
ansMap[nextY][nextX] = ansMap[now.y][now.x] + 1;
q.add(new Point(nextX, nextY));
ans = Math.max(ans, ansMap[nextY][nextX]);
}
}
}
}
System.out.println(ans);
}
static class Point {
int x, y;
Point(int x, int y) {
this.x = x;
this.y = y;
}
}
}
jp_ste