結果

問題 No.179 塗り分け
ユーザー yudedako
提出日時 2020-08-27 11:14:54
言語 Kotlin
(2.1.0)
結果
WA  
実行時間 -
コード長 1,146 bytes
コンパイル時間 14,867 ms
コンパイル使用メモリ 437,308 KB
実行使用メモリ 52,888 KB
最終ジャッジ日時 2024-11-07 15:34:20
合計ジャッジ時間 29,433 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 6
other AC * 37 WA * 3
権限があれば一括ダウンロードができます

ソースコード

diff #


fun main() {
    val (height, width) = readLine()!!.trim().split(' ').map(String::toInt)
    val square = Array(height){readLine()!!.trim()}
    val type = Array(height){IntArray(width){-1} }
    val blackCell = (0 until height).flatMap{h -> (0 until width).filter{w -> square[h][w] == '#'}.map{w -> h to w}}
    var hasPair = true
    outer@for (dh in 0 until height) {
        for (dw in -width + 1 until width) {
            if (dh == 0 && dw == 0) continue
            val count = (dh * width * 2) + dw + width
            hasPair = true
            for ((h, w) in blackCell) {
                if (type[h][w] >= count) continue
                type[h][w] = count
                if (h + dh !in 0 until height || w + dw !in 0 until width) {
                    hasPair = false
                    break
                }
                if (square[h + dh][w + dw] != '#') {
                    hasPair = false
                    break
                }
                type[h + dh][w + dw] = count
            }
            if (hasPair) {
                break@outer
            }
        }
    }
    println(if (hasPair) "YES" else "NO")
}
0