結果
| 問題 |
No.157 2つの空洞
|
| コンテスト | |
| ユーザー |
バカらっく
|
| 提出日時 | 2019-11-09 03:03:04 |
| 言語 | Kotlin (2.1.0) |
| 結果 |
AC
|
| 実行時間 | 378 ms / 2,000 ms |
| コード長 | 2,577 bytes |
| コンパイル時間 | 15,896 ms |
| コンパイル使用メモリ | 447,776 KB |
| 実行使用メモリ | 53,124 KB |
| 最終ジャッジ日時 | 2024-09-15 03:54:49 |
| 合計ジャッジ時間 | 22,770 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 16 |
コンパイルメッセージ
Main.kt:3:10: warning: parameter 'arr' is never used
fun main(arr:Array<String>) {
^
ソースコード
import java.util.*
fun main(arr:Array<String>) {
val (w,h) = readLine()!!.split(" ").map { it.toInt() }
val map = (1..h).map { readLine()!!.toCharArray() }
val groupMap = (1..h).map { (1..w).map { 0 }.toMutableList() }.toMutableList()
var mapIndex = 1
for(r in map.indices) {
for(c in map[r].indices) {
if(map[r][c] == '#') {
continue
}
if(groupMap[r][c] > 0) {
continue
}
val queue = LinkedList<Pos>()
queue.add(Pos(r,c))
groupMap[r][c] = mapIndex
while (queue.isNotEmpty()) {
val current = queue.pop()
for(newR in (current.row-1..current.row+1)) {
if(newR < 0) {
continue
}
if(newR >= h) {
continue
}
for(newC in (current.col-1..current.col+1)) {
if(newC < 0) {
continue
}
if(newC >= w) {
continue
}
if(newR == current.row && newC == current.col) {
continue
}
if(newR != current.row && newC != current.col) {
continue
}
if(groupMap[newR][newC] > 0) {
continue
}
if(map[newR][newC] == '#') {
continue
}
groupMap[newR][newC] = mapIndex
queue.push(Pos(newR,newC))
}
}
}
mapIndex ++
}
}
var ans = w*h
for(r1 in map.indices) {
for(c1 in map[r1].indices) {
if(map[r1][c1] == '#') {
continue
}
for(r2 in map.indices) {
for(c2 in map[r2].indices) {
if(map[r2][c2] == '#') {
continue
}
if(groupMap[r1][c1] == groupMap[r2][c2]) {
continue
}
val dist = Math.abs(r1-r2) + Math.abs(c1-c2) - 1
ans = Math.min(ans, dist)
}
}
}
}
println(ans)
}
class Pos(val row:Int, val col:Int)
バカらっく