結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 97 ms
40,312 KB
testcase_01 AC 116 ms
41,240 KB
testcase_02 AC 116 ms
40,748 KB
testcase_03 AC 94 ms
40,216 KB
testcase_04 AC 99 ms
40,080 KB
testcase_05 AC 113 ms
41,180 KB
testcase_06 AC 102 ms
40,204 KB
testcase_07 AC 110 ms
41,492 KB
testcase_08 AC 107 ms
41,264 KB
testcase_09 AC 105 ms
40,076 KB
testcase_10 AC 118 ms
41,364 KB
testcase_11 AC 122 ms
41,688 KB
testcase_12 AC 104 ms
40,316 KB
testcase_13 AC 168 ms
42,280 KB
testcase_14 AC 151 ms
42,200 KB
testcase_15 AC 233 ms
44,932 KB
testcase_16 AC 300 ms
49,340 KB
testcase_17 AC 644 ms
82,516 KB
testcase_18 TLE -
testcase_19 AC 884 ms
134,716 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 < 500; 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