結果
問題 | No.402 最も海から遠い場所 |
ユーザー | tenten |
提出日時 | 2021-05-17 18:11:12 |
言語 | Java21 (openjdk 21) |
結果 |
RE
|
実行時間 | - |
コード長 | 2,587 bytes |
コンパイル時間 | 2,791 ms |
コンパイル使用メモリ | 77,824 KB |
実行使用メモリ | 100,836 KB |
最終ジャッジ日時 | 2024-04-16 06:58:28 |
合計ジャッジ時間 | 8,498 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 52 ms
36,884 KB |
testcase_01 | AC | 50 ms
36,860 KB |
testcase_02 | AC | 56 ms
37,060 KB |
testcase_03 | AC | 52 ms
37,084 KB |
testcase_04 | AC | 51 ms
37,192 KB |
testcase_05 | AC | 50 ms
36,940 KB |
testcase_06 | AC | 51 ms
36,888 KB |
testcase_07 | RE | - |
testcase_08 | AC | 52 ms
36,844 KB |
testcase_09 | AC | 51 ms
36,816 KB |
testcase_10 | RE | - |
testcase_11 | AC | 53 ms
37,160 KB |
testcase_12 | WA | - |
testcase_13 | AC | 100 ms
38,964 KB |
testcase_14 | RE | - |
testcase_15 | RE | - |
testcase_16 | RE | - |
testcase_17 | AC | 512 ms
71,156 KB |
testcase_18 | AC | 577 ms
100,676 KB |
testcase_19 | AC | 619 ms
100,836 KB |
testcase_20 | AC | 578 ms
100,640 KB |
testcase_21 | AC | 585 ms
100,532 KB |
ソースコード
import java.io.*; import java.util.*; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int h = sc.nextInt(); int w = sc.nextInt(); char[][] field = new char[h][]; for (int i = 0; i < h; i++) { field[i] = sc.next().toCharArray(); } int[][] dists = new int[h + 2][w + 2]; for (int i = 0; i < h + 2; i++) { if (i >= 1 && i <= h) { Arrays.fill(dists[i], Integer.MAX_VALUE); dists[i][0] = 0; dists[i][h + 1] = 0; for (int j = 0; j < w; j++) { if (field[i - 1][j] == '.') { dists[i][j + 1] = 0; } } } } for (int i = 1; i <= h; i++) { for (int j = 1; j <= w; j++) { int min = Math.min(dists[i][j - 1], Math.min(dists[i - 1][j - 1], dists[i - 1][j])); dists[i][j] = Math.min(dists[i][j], min + 1); } for (int j = w; j>= 1; j--) { int min = Math.min(dists[i][j + 1], Math.min(dists[i - 1][j + 1], dists[i - 1][j])); dists[i][j] = Math.min(dists[i][j], min + 1); } } for (int i = h; i >= 1; i--) { for (int j = 1; j <= w; j++) { int min = Math.min(dists[i][j - 1], Math.min(dists[i + 1][j - 1], dists[i + 1][j])); dists[i][j] = Math.min(dists[i][j], min + 1); } for (int j = w; j>= 1; j--) { int min = Math.min(dists[i][j + 1], Math.min(dists[i + 1][j + 1], dists[i + 1][j])); dists[i][j] = Math.min(dists[i][j], min + 1); } } int ans = 0; for (int i = 1; i <= h; i++) { for (int j = 1; j <= w; j++) { ans = Math.max(ans, dists[i][j]); } } System.out.println(ans); } } class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); public Scanner() throws Exception { } public int nextInt() throws Exception { return Integer.parseInt(next()); } public long nextLong() throws Exception { return Long.parseLong(next()); } public String next() throws Exception { if (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }