結果

問題 No.402 最も海から遠い場所
ユーザー kano_townkano_town
提出日時 2016-07-23 00:09:55
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 2,229 bytes
コンパイル時間 3,827 ms
コンパイル使用メモリ 78,116 KB
実行使用メモリ 145,080 KB
最終ジャッジ日時 2024-04-24 06:39:43
合計ジャッジ時間 18,085 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 133 ms
41,420 KB
testcase_01 AC 118 ms
41,228 KB
testcase_02 AC 137 ms
41,424 KB
testcase_03 AC 114 ms
39,944 KB
testcase_04 AC 130 ms
41,404 KB
testcase_05 AC 133 ms
41,096 KB
testcase_06 AC 131 ms
41,360 KB
testcase_07 AC 130 ms
41,132 KB
testcase_08 AC 124 ms
41,052 KB
testcase_09 AC 129 ms
41,088 KB
testcase_10 AC 133 ms
41,404 KB
testcase_11 AC 138 ms
41,264 KB
testcase_12 AC 122 ms
40,240 KB
testcase_13 AC 183 ms
41,992 KB
testcase_14 AC 175 ms
42,260 KB
testcase_15 AC 264 ms
44,872 KB
testcase_16 AC 381 ms
49,540 KB
testcase_17 AC 740 ms
82,752 KB
testcase_18 TLE -
testcase_19 AC 1,035 ms
135,772 KB
testcase_20 TLE -
testcase_21 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Yukicoder402 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int h = sc.nextInt() + 2, w = sc.nextInt() + 2;
        String[] s = new String[h];
        int[] map = new int[h * w];
        int[] map_buf = new int[h * w];
        int[] dx = {-1, 0, 1, -1, 1, -1, 0, 1};
        int[] dy = {-1, -1, -1, 0, 0, 1, 1, 1};
        for (int i = 0; i < h; i++) {
            if (i == 0 || i == h - 1) {
                for (int x = 0; x < w; x++) {
                    map[i * w + x] = 0;
                    map_buf[i * w + x] = 0;
                }
            }
            if (i == 0 || i == h - 1) continue;
            s[i] = sc.next();
            for (int x = 0; x < w; x++) {
                if (x == 0 || x == w - 1) {
                    map[i * w + x] = 0;
                    map_buf[i * w + x] = 0;
                } else if (s[i].charAt(x - 1) == '.') {
                    map[i * w + x] = 0;
                    map_buf[i * w + x] = 0;
                } else {
                    map[i * w + x] = 1;
                    map_buf[i * w + x] = 1;
                }
            }
        }

        int cnt, k;
        for (k = 1; k < 1500; k++) {
            cnt = 0;
            for (int y = k; y < h - k; y++) {
                for (int x = k; x < w - k; x++) {
                    if (map[y * w + x] == 1) {
                        for (int p = 0; p < 8; p++) {
                            if (map[(y + dy[p]) * w + (x + dx[p])] == 0) {
                                map_buf[y * w + x] = 0;
                                cnt++;
                                break;
                            }
                        }
                    }
                }
            }
            for (int y = k; y < h - k; y++) {
                for (int x = k; x < w - k; x++) {
/*                    if (map[y * w + x] == 1)
                        System.out.print("#");
                    else
                        System.out.print(".");
        */
                    map[y * w + x] = map_buf[y * w + x];
                }
            }
            if (cnt == 0) break;
        }
        System.out.println(k-1);
    }
}
0