結果

問題 No.179 塗り分け
ユーザー yudedakoyudedako
提出日時 2020-08-27 11:16:42
言語 Kotlin
(1.9.23)
結果
AC  
実行時間 340 ms / 3,000 ms
コード長 1,219 bytes
コンパイル時間 14,085 ms
コンパイル使用メモリ 421,868 KB
実行使用メモリ 53,432 KB
最終ジャッジ日時 2023-09-30 21:32:04
合計ジャッジ時間 30,087 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 295 ms
52,796 KB
testcase_01 AC 300 ms
53,056 KB
testcase_02 AC 294 ms
52,780 KB
testcase_03 AC 295 ms
52,940 KB
testcase_04 AC 294 ms
53,008 KB
testcase_05 AC 302 ms
52,740 KB
testcase_06 AC 300 ms
52,836 KB
testcase_07 AC 303 ms
53,432 KB
testcase_08 AC 303 ms
52,764 KB
testcase_09 AC 305 ms
53,016 KB
testcase_10 AC 307 ms
53,032 KB
testcase_11 AC 303 ms
52,928 KB
testcase_12 AC 340 ms
53,344 KB
testcase_13 AC 293 ms
53,068 KB
testcase_14 AC 295 ms
52,888 KB
testcase_15 AC 291 ms
52,784 KB
testcase_16 AC 293 ms
53,180 KB
testcase_17 AC 293 ms
52,928 KB
testcase_18 AC 308 ms
52,952 KB
testcase_19 AC 307 ms
52,908 KB
testcase_20 AC 317 ms
53,156 KB
testcase_21 AC 311 ms
52,952 KB
testcase_22 AC 310 ms
52,956 KB
testcase_23 AC 307 ms
53,216 KB
testcase_24 AC 308 ms
53,064 KB
testcase_25 AC 306 ms
53,124 KB
testcase_26 AC 304 ms
52,884 KB
testcase_27 AC 304 ms
53,384 KB
testcase_28 AC 300 ms
53,048 KB
testcase_29 AC 305 ms
53,220 KB
testcase_30 AC 304 ms
53,000 KB
testcase_31 AC 307 ms
52,940 KB
testcase_32 AC 306 ms
53,112 KB
testcase_33 AC 310 ms
53,372 KB
testcase_34 AC 299 ms
52,976 KB
testcase_35 AC 303 ms
52,940 KB
testcase_36 AC 289 ms
53,152 KB
testcase_37 AC 287 ms
52,992 KB
testcase_38 AC 286 ms
52,944 KB
testcase_39 AC 288 ms
52,836 KB
testcase_40 AC 287 ms
52,956 KB
testcase_41 AC 289 ms
53,052 KB
testcase_42 AC 286 ms
53,116 KB
testcase_43 AC 294 ms
52,824 KB
testcase_44 AC 299 ms
52,760 KB
testcase_45 AC 289 ms
52,956 KB
権限があれば一括ダウンロードができます

ソースコード

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}}
    if (blackCell.size < 2) {
        println("NO")
        return
    }
    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