結果
問題 |
No.402 最も海から遠い場所
|
ユーザー |
![]() |
提出日時 | 2016-08-12 15:26:08 |
言語 | Java (openjdk 23) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,730 bytes |
コンパイル時間 | 2,578 ms |
コンパイル使用メモリ | 77,460 KB |
実行使用メモリ | 124,612 KB |
最終ジャッジ日時 | 2024-11-07 12:07:29 |
合計ジャッジ時間 | 14,613 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 WA * 1 |
other | AC * 12 WA * 5 TLE * 1 -- * 1 |
ソースコード
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; } if(map[i][j] == '.') { 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; } } } } } 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(); } }