結果
問題 | No.402 最も海から遠い場所 |
ユーザー |
![]() |
提出日時 | 2016-08-11 19:27:55 |
言語 | Java21 (openjdk 21) |
結果 |
TLE
|
実行時間 | - |
コード長 | 2,461 bytes |
コンパイル時間 | 2,437 ms |
コンパイル使用メモリ | 79,456 KB |
実行使用メモリ | 719,044 KB |
最終ジャッジ日時 | 2024-04-25 01:34:53 |
合計ジャッジ時間 | 13,723 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 135 ms
41,652 KB |
testcase_01 | AC | 132 ms
41,644 KB |
testcase_02 | AC | 143 ms
41,468 KB |
testcase_03 | AC | 134 ms
41,232 KB |
testcase_04 | AC | 132 ms
41,312 KB |
testcase_05 | AC | 135 ms
41,396 KB |
testcase_06 | AC | 131 ms
41,072 KB |
testcase_07 | AC | 134 ms
41,216 KB |
testcase_08 | AC | 119 ms
40,104 KB |
testcase_09 | AC | 131 ms
41,408 KB |
testcase_10 | AC | 131 ms
41,140 KB |
testcase_11 | AC | 142 ms
41,348 KB |
testcase_12 | AC | 138 ms
41,552 KB |
testcase_13 | AC | 229 ms
43,964 KB |
testcase_14 | AC | 190 ms
42,380 KB |
testcase_15 | AC | 393 ms
57,272 KB |
testcase_16 | AC | 495 ms
64,152 KB |
testcase_17 | AC | 2,143 ms
326,796 KB |
testcase_18 | AC | 2,522 ms
242,356 KB |
testcase_19 | TLE | - |
testcase_20 | AC | 2,265 ms
136,548 KB |
testcase_21 | MLE | - |
ソースコード
import java.io.PrintWriter; import java.util.LinkedList; import java.util.Scanner; public class Main { static Scanner scan = new Scanner(System.in); static PrintWriter out = new PrintWriter(System.out); static int H, W; static char[][] map; static int [][] ansMap; static int ans = 0; public static void main(String[] args) { String line = scan.nextLine(); String values[] = line.split(" "); H = Integer.parseInt(values[0]); W = Integer.parseInt(values[1]);; LinkedList<Point> q = new LinkedList<>(); map = new char[H+2][W+2]; ansMap = new int[H+2][W+2]; for(int i=0; i<map.length; i++) { for(int j=0; j<map[0].length; j++) { if(i==0 || i==map.length-1 || j==0 || j==map[0].length-1) { map[i][j] = '.'; q.add(new Point(j, i)); } } } for(int i=0; i<H; i++) { line = scan.nextLine(); for(int j=0; j<W; j++) { map[i+1][j+1] = line.charAt(j); if(map[i+1][j+1] == '.') { q.add(new Point(j+1,i+1)); } } } int[] dx = {-1, 0, 1, -1, 1, -1, 0, 1}; int[] dy = {-1, -1, -1, 0, 0, 1, 1, 1}; while(!q.isEmpty()) { Point now = q.poll(); for(int i=0; i<dx.length; i++) { int nextX = now.x + dx[i]; int nextY = now.y + dy[i]; if(nextX >= 0 && nextX < map[0].length && nextY >= 0 && nextY < map.length) { if(map[nextY][nextX] == '#' && ansMap[nextY][nextX] == 0) { ansMap[nextY][nextX] = ansMap[now.y][now.x] + 1; q.add(new Point(nextX, nextY)); ans = Math.max(ans, ansMap[nextY][nextX]); } } } } System.out.println(ans); } static void out() { for(int i=0; i<map.length; i++) { for(int j=0; j<map[0].length; j++) { System.out.print(map[i][j]); } System.out.println(); } } static class Point { int x, y; Point(int x, int y) { this.x = x; this.y = y; } } }