結果
問題 | No.402 最も海から遠い場所 |
ユーザー |
![]() |
提出日時 | 2016-08-12 15:54:40 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 2,633 ms / 3,000 ms |
コード長 | 3,062 bytes |
コンパイル時間 | 2,484 ms |
コンパイル使用メモリ | 79,456 KB |
実行使用メモリ | 118,652 KB |
最終ジャッジ日時 | 2024-11-07 12:08:31 |
合計ジャッジ時間 | 13,343 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 19 |
ソースコード
import java.io.PrintWriter;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[] dx = {-1, 0, 1, -1, 1, -1, 0, 1};static int[] dy = {-1, -1, -1, 0, 0, 1, 1, 1};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][W];ansMap = new int[H][W];for(int i=0; i<H; i++) {line = scan.nextLine();for(int j=0; j<W; j++) {map[i][j] = line.charAt(j);if(map[i][j] == '#') {ansMap[i][j] = -1;}if((i==0 || i==H-1 || j==0 || j==W-1) && map[i][j] == '#') {ansMap[i][j] = 1;}}}boolean dotFind = false;for(int i=0; i<H; i++) {for(int j=0; j<W; j++) {if(map[i][j] == '.') {dotFind = true;for(int k=0; k<dx.length; k++) {int nextX = j + dx[k];int nextY = i + dy[k];if(nextX >= 0 && nextX < W && nextY >= 0 && nextY < H && map[nextY][nextX] == '#') {ansMap[nextY][nextX] = 1;}}}}}if(!dotFind) {int minLen = Math.min(W, H);System.out.println(minLen==1? 1 : minLen/2);return;}for(int count=1; count<=1500; count++) {//out();boolean find = false;for(int i=0; i<H; i++) {for(int j=0; j<W; j++) {if(ansMap[i][j] == count) {for(int k=0; k<dx.length; k++) {int nextX = j + dx[k];int nextY = i + dy[k];if(nextX >= 0 && nextX < W && nextY >= 0 && nextY < H && ansMap[nextY][nextX] == -1) {ansMap[nextY][nextX] = (count+1);find = true;}}}}}if(find == false) {System.out.println(count);break;}}}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();}System.out.println();}}