結果
問題 | No.402 最も海から遠い場所 |
ユーザー | tenten |
提出日時 | 2021-01-26 08:06:06 |
言語 | Java21 (openjdk 21) |
結果 |
MLE
|
実行時間 | - |
コード長 | 3,083 bytes |
コンパイル時間 | 2,364 ms |
コンパイル使用メモリ | 75,864 KB |
実行使用メモリ | 696,856 KB |
最終ジャッジ日時 | 2023-09-05 11:34:11 |
合計ジャッジ時間 | 12,930 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 46 ms
49,436 KB |
testcase_01 | AC | 46 ms
49,712 KB |
testcase_02 | AC | 68 ms
50,228 KB |
testcase_03 | AC | 43 ms
49,988 KB |
testcase_04 | AC | 44 ms
49,312 KB |
testcase_05 | AC | 45 ms
49,432 KB |
testcase_06 | AC | 44 ms
49,484 KB |
testcase_07 | AC | 44 ms
49,368 KB |
testcase_08 | AC | 43 ms
49,408 KB |
testcase_09 | AC | 47 ms
49,484 KB |
testcase_10 | AC | 46 ms
49,504 KB |
testcase_11 | AC | 75 ms
52,092 KB |
testcase_12 | AC | 53 ms
50,424 KB |
testcase_13 | AC | 199 ms
59,920 KB |
testcase_14 | AC | 128 ms
54,720 KB |
testcase_15 | AC | 651 ms
101,664 KB |
testcase_16 | AC | 796 ms
111,508 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; int[][] costs = new int[h + 2][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); } }