結果

問題 No.402 最も海から遠い場所
ユーザー jp_stejp_ste
提出日時 2016-08-12 15:25:55
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 2,746 bytes
コンパイル時間 2,790 ms
コンパイル使用メモリ 78,160 KB
実行使用メモリ 124,564 KB
最終ジャッジ日時 2024-04-25 02:32:54
合計ジャッジ時間 14,139 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 110 ms
45,428 KB
testcase_01 AC 122 ms
41,304 KB
testcase_02 WA -
testcase_03 AC 132 ms
40,952 KB
testcase_04 AC 140 ms
40,476 KB
testcase_05 AC 115 ms
40,632 KB
testcase_06 AC 124 ms
41,196 KB
testcase_07 AC 123 ms
41,368 KB
testcase_08 AC 108 ms
39,840 KB
testcase_09 WA -
testcase_10 AC 113 ms
40,052 KB
testcase_11 AC 129 ms
41,352 KB
testcase_12 AC 125 ms
41,104 KB
testcase_13 WA -
testcase_14 AC 177 ms
41,512 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 1,699 ms
118,456 KB
testcase_19 AC 1,166 ms
118,792 KB
testcase_20 TLE -
testcase_21 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

package No402;

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();
    }
}
0