結果

問題 No.179 塗り分け
ユーザー IJKTanabeIJKTanabe
提出日時 2019-03-24 20:02:11
言語 Kotlin
(1.9.23)
結果
AC  
実行時間 910 ms / 3,000 ms
コード長 2,784 bytes
コンパイル時間 19,792 ms
コンパイル使用メモリ 428,688 KB
実行使用メモリ 65,956 KB
最終ジャッジ日時 2023-09-30 21:11:20
合計ジャッジ時間 42,684 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 302 ms
53,080 KB
testcase_01 AC 307 ms
52,952 KB
testcase_02 AC 308 ms
52,936 KB
testcase_03 AC 306 ms
52,916 KB
testcase_04 AC 303 ms
53,284 KB
testcase_05 AC 474 ms
60,824 KB
testcase_06 AC 437 ms
60,088 KB
testcase_07 AC 481 ms
59,088 KB
testcase_08 AC 306 ms
52,952 KB
testcase_09 AC 322 ms
53,320 KB
testcase_10 AC 574 ms
62,412 KB
testcase_11 AC 565 ms
62,596 KB
testcase_12 AC 910 ms
63,680 KB
testcase_13 AC 314 ms
53,228 KB
testcase_14 AC 322 ms
53,292 KB
testcase_15 AC 298 ms
53,344 KB
testcase_16 AC 301 ms
53,056 KB
testcase_17 AC 300 ms
52,968 KB
testcase_18 AC 574 ms
61,928 KB
testcase_19 AC 556 ms
61,396 KB
testcase_20 AC 691 ms
63,196 KB
testcase_21 AC 634 ms
61,268 KB
testcase_22 AC 633 ms
61,720 KB
testcase_23 AC 513 ms
59,852 KB
testcase_24 AC 632 ms
61,672 KB
testcase_25 AC 550 ms
61,436 KB
testcase_26 AC 516 ms
62,120 KB
testcase_27 AC 645 ms
62,956 KB
testcase_28 AC 544 ms
63,420 KB
testcase_29 AC 681 ms
65,448 KB
testcase_30 AC 515 ms
63,048 KB
testcase_31 AC 681 ms
65,452 KB
testcase_32 AC 529 ms
62,800 KB
testcase_33 AC 696 ms
65,532 KB
testcase_34 AC 544 ms
63,116 KB
testcase_35 AC 712 ms
65,956 KB
testcase_36 AC 301 ms
52,996 KB
testcase_37 AC 303 ms
53,108 KB
testcase_38 AC 301 ms
53,648 KB
testcase_39 AC 299 ms
52,900 KB
testcase_40 AC 304 ms
53,044 KB
testcase_41 AC 304 ms
52,904 KB
testcase_42 AC 300 ms
52,980 KB
testcase_43 AC 444 ms
61,344 KB
testcase_44 AC 472 ms
61,072 KB
testcase_45 AC 327 ms
53,252 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.kt:1:10: warning: parameter 'args' is never used
fun main(args: Array<String>) {
         ^
Main.kt:28:5: warning: parameter 'cellsList' is never used
    cellsList: List<List<String>>,
    ^
Main.kt:31:5: warning: parameter 'W' is never used
    W: Int,
    ^

ソースコード

diff #

fun main(args: Array<String>) {
    val (H, W) = readLine()!!.split(" ").map(String::toInt)
    // 入力を各セルごとの二次元リストに
    val cellsList: List<List<String>> = List(H) { readLine()!!.chunked(1) }
    // 行ごとに、黒色セルのインデックスのリストを取得
    val blackIndices = cellsList.map {
        it.mapIndexedNotNull { index, value ->
            if (value == "#") index else null
        }
    }

/*
    //Check Print
    cellsList.forEach { println(it) }
    blackIndices.forEach { println(it) }
*/

    for (vecY in (-H + 1)..(H - 1)) for (vecX in (-W + 1)..(W - 1)) {
        if (tryPaintB(cellsList, blackIndices, H, W, vecY, vecX)) {
            println("YES")
            return
        }
    }
    println("NO")
}

fun tryPaintB(
    cellsList: List<List<String>>,
    blackIndices: List<List<Int>>,
    H: Int,
    W: Int,
    vecY: Int,
    vecX: Int
): Boolean {

    //val cells = cellsList.map { it.toMutableList() }
    val rangeY =
        if (vecY < 0)
            ((H - 1) downTo 0).toList()
        else
            (0 until H).toList()

    val indices =
        if (vecX < 0)
            blackIndices.map { it.reversed().toMutableList() }
        else
            blackIndices.map { it.toMutableList() }

    var flg: Boolean? = null

/*
    //Check Print
    println("vec = $vecY, $vecX")
    println("Y_range = $rangeY")
    println("blackIndices =")
    indices.forEach { println(it) }
*/

    for (y in rangeY) {
        while (indices[y].isNotEmpty()) {
            var trgY = y
            var trgX = indices[y].first()

            while (rangeY.contains(trgY) && indices[trgY].contains(trgX)) {
                //cells[y][x] = "R"
                indices[trgY].remove(trgX)
                trgY += vecY
                trgX += vecX
                if (rangeY.contains(trgY) && indices[trgY].contains(trgX)) {
                    //cells[trgY][trgX] = "B"
                    indices[trgY].remove(trgX)
                    if (flg == null) flg = true
                    trgY += vecY
                    trgX += vecX
                } else {
                    //flg = false
                    return false
                }
            }
//            if (rangeY.contains(trgY) && indices[trgY].contains(trgX)) {
//                //cells[trgY][trgX] = "B"
//                indices[trgY].remove(trgX)
//                if (flg == null) flg = true
//            } else {
//                //flg = false
//                return false
//            }
        }
    }

/*
    //Check Print
    cells.forEach { println(it.joinToString("")) }
    println(flg)
    println(" ")
*/

    return flg ?: false
}
0