結果
| 問題 |
No.402 最も海から遠い場所
|
| ユーザー |
tenten
|
| 提出日時 | 2021-01-26 08:06:06 |
| 言語 | Java (openjdk 23) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 3,083 bytes |
| コンパイル時間 | 2,494 ms |
| コンパイル使用メモリ | 78,616 KB |
| 実行使用メモリ | 104,176 KB |
| 最終ジャッジ日時 | 2024-06-23 07:12:31 |
| 合計ジャッジ時間 | 13,227 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 14 TLE * 1 -- * 4 |
ソースコード
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);
}
}
tenten