結果
| 問題 |
No.402 最も海から遠い場所
|
| コンテスト | |
| ユーザー |
jp_ste
|
| 提出日時 | 2016-08-11 19:27:55 |
| 言語 | Java (openjdk 23) |
| 結果 |
MLE
|
| 実行時間 | - |
| コード長 | 2,461 bytes |
| コンパイル時間 | 2,174 ms |
| コンパイル使用メモリ | 79,052 KB |
| 実行使用メモリ | 724,452 KB |
| 最終ジャッジ日時 | 2024-11-07 11:02:22 |
| 合計ジャッジ時間 | 15,411 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 16 MLE * 1 -- * 2 |
ソースコード
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) {
String line = scan.nextLine();
String values[] = line.split(" ");
H = Integer.parseInt(values[0]);
W = Integer.parseInt(values[1]);;
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++) {
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));
}
}
}
for(int i=0; i<H; i++) {
line = scan.nextLine();
for(int j=0; j<W; j++) {
map[i+1][j+1] = line.charAt(j);
if(map[i+1][j+1] == '.') {
q.add(new Point(j+1,i+1));
}
}
}
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 void out() {
for(int i=0; i<map.length; i++) {
for(int j=0; j<map[0].length; j++) {
System.out.print(map[i][j]);
}
System.out.println();
}
}
static class Point {
int x, y;
Point(int x, int y) {
this.x = x;
this.y = y;
}
}
}
jp_ste