結果
問題 | No.402 最も海から遠い場所 |
ユーザー | tenten |
提出日時 | 2021-01-26 08:30:45 |
言語 | Java21 (openjdk 21) |
結果 |
MLE
|
実行時間 | - |
コード長 | 3,036 bytes |
コンパイル時間 | 2,546 ms |
コンパイル使用メモリ | 75,116 KB |
実行使用メモリ | 700,572 KB |
最終ジャッジ日時 | 2023-09-05 11:51:54 |
合計ジャッジ時間 | 12,265 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 51 ms
49,104 KB |
testcase_01 | AC | 46 ms
47,188 KB |
testcase_02 | AC | 79 ms
50,716 KB |
testcase_03 | AC | 44 ms
49,248 KB |
testcase_04 | AC | 45 ms
49,100 KB |
testcase_05 | AC | 46 ms
49,148 KB |
testcase_06 | AC | 45 ms
48,976 KB |
testcase_07 | AC | 44 ms
49,144 KB |
testcase_08 | AC | 45 ms
49,160 KB |
testcase_09 | AC | 46 ms
49,164 KB |
testcase_10 | AC | 46 ms
48,992 KB |
testcase_11 | AC | 75 ms
51,892 KB |
testcase_12 | AC | 53 ms
50,532 KB |
testcase_13 | AC | 194 ms
59,828 KB |
testcase_14 | AC | 127 ms
54,680 KB |
testcase_15 | AC | 653 ms
101,844 KB |
testcase_16 | AC | 795 ms
109,944 KB |
testcase_17 | MLE | - |
testcase_18 | -- | - |
testcase_19 | -- | - |
testcase_20 | -- | - |
testcase_21 | -- | - |
ソースコード
import java.util.*; import java.io.*; public class Main { public static void main(String[] args) throws Exception{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String[] first = br.readLine().split(" ", 2); int h = Integer.parseInt(first[0]); int w = Integer.parseInt(first[1]); int w2 = w + 2; HashSet<Integer> current = new HashSet<>(); for (int i = 0; i < w2; i++) { current.add(i); current.add((h + 1) * w2 + i); } char[][] field = new char[h][]; for (int i = 0; i < h; i++) { field[i] = br.readLine().toCharArray(); current.add((i + 1) * w2); current.add((i + 1) * w2 + w + 1); for (int j = 0; j < w; j++) { if (field[i][j] == '.') { current.add((i + 1) * w2 + j + 1); } } } HashSet<Integer> used = new HashSet<>(); used.addAll(current); int idx = 0; while (used.size() < (h + 2) * (w + 2)) { HashSet<Integer> next = new HashSet<>(); for (int x : current) { if (x % w2 > 0) { int tmp = x - 1; if (!used.contains(tmp)) { next.add(tmp); } if (x / w2 > 0) { int tmp2 = tmp - w2; if (!used.contains(tmp2)) { next.add(tmp2); } } if (x / w2 < h + 1) { int tmp2 = tmp + w2; if (!used.contains(tmp2)) { next.add(tmp2); } } } if (x % w2 < w + 1) { int tmp = x + 1; if (!used.contains(tmp)) { next.add(tmp); } if (x / w2 > 0) { int tmp2 = tmp - w2; if (!used.contains(tmp2)) { next.add(tmp2); } } if (x / w2 < h + 1) { int tmp2 = tmp + w2; if (!used.contains(tmp2)) { next.add(tmp2); } } } if (x / w2 > 0) { int tmp = x - w2; if (!used.contains(tmp)) { next.add(tmp); } } if (x / w2 < h + 1) { int tmp = x + w2; if (!used.contains(tmp)) { next.add(tmp); } } } idx++; used.addAll(next); current = next; } System.out.println(idx); } }