結果
| 問題 |
No.402 最も海から遠い場所
|
| コンテスト | |
| ユーザー |
jp_ste
|
| 提出日時 | 2016-08-12 04:08:55 |
| 言語 | Java (openjdk 23) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 2,540 bytes |
| コンパイル時間 | 2,273 ms |
| コンパイル使用メモリ | 79,632 KB |
| 実行使用メモリ | 718,636 KB |
| 最終ジャッジ日時 | 2024-11-07 11:57:39 |
| 合計ジャッジ時間 | 19,176 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 17 TLE * 1 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;
public static void main(String[] args) {
String line = scan.nextLine();
String values[] = line.split(" ");
H = Integer.parseInt(values[0]);
W = Integer.parseInt(values[1]);;
map = new char[H+2][W+2];
ansMap = new int[H+2][W+2];
LinkedList<Node> q = new LinkedList<>();
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 Node(j, i, 0));
}
}
}
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 Node(j+1, i+1, 0));
} else {
ansMap[i+1][j+1] = -1;
}
}
}
int[] dx = {-1, 0, 1, -1, 1, -1, 0, 1};
int[] dy = {-1, -1, -1, 0, 0, 1, 1, 1};
int ans = 1;
while(!q.isEmpty()) {
Node now = q.poll();
for(int i=0; i<dx.length; i++) {
int nextX = now.x + dx[i];
int nextY = now.y + dy[i];
int nextV = now.v + 1;
if(nextX >= 0 && nextX < ansMap[0].length && nextY >= 0 && nextY < ansMap.length && ansMap[nextY][nextX] == -1) {
ansMap[nextY][nextX] = nextV;
q.add(new Node(nextX, nextY, nextV));
ans = Math.max(ans, ansMap[nextY][nextX]);
}
}
}
//out();
System.out.println(ans);
}
static void out() {
for(int i=0; i<ansMap.length; i++) {
for(int j=0; j<ansMap[0].length; j++) {
System.out.printf("%2d " , ansMap[i][j]);
}
System.out.println();
}
}
static class Node {
int x, y, v;
Node(int x, int y, int v) {
this.x = x;
this.y = y;
this.v = v;
}
}
}
jp_ste