結果

問題 No.157 2つの空洞
ユーザー バカらっくバカらっく
提出日時 2019-11-09 03:01:39
言語 Kotlin
(1.9.23)
結果
RE  
実行時間 -
コード長 2,573 bytes
コンパイル時間 16,221 ms
コンパイル使用メモリ 431,476 KB
実行使用メモリ 55,200 KB
最終ジャッジ日時 2023-10-13 06:39:06
合計ジャッジ時間 22,070 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 AC 291 ms
53,116 KB
testcase_02 AC 289 ms
53,332 KB
testcase_03 RE -
testcase_04 AC 291 ms
53,104 KB
testcase_05 AC 293 ms
52,880 KB
testcase_06 AC 287 ms
53,092 KB
testcase_07 AC 287 ms
52,872 KB
testcase_08 AC 287 ms
53,060 KB
testcase_09 AC 290 ms
52,952 KB
testcase_10 AC 293 ms
52,900 KB
testcase_11 AC 290 ms
52,920 KB
testcase_12 AC 296 ms
52,916 KB
testcase_13 AC 304 ms
53,056 KB
testcase_14 AC 301 ms
52,896 KB
testcase_15 AC 300 ms
53,152 KB
testcase_16 AC 298 ms
53,256 KB
testcase_17 AC 352 ms
54,036 KB
testcase_18 AC 300 ms
53,028 KB
testcase_19 AC 295 ms
52,776 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.kt:3:10: warning: parameter 'arr' is never used
fun main(arr:Array<String>) {
         ^

ソースコード

diff #

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.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)
0