結果

問題 No.179 塗り分け
ユーザー IJKTanabeIJKTanabe
提出日時 2019-03-24 18:49:08
言語 Kotlin
(1.9.23)
結果
AC  
実行時間 880 ms / 3,000 ms
コード長 2,201 bytes
コンパイル時間 17,713 ms
コンパイル使用メモリ 424,788 KB
実行使用メモリ 62,100 KB
最終ジャッジ日時 2023-09-30 21:09:54
合計ジャッジ時間 40,463 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 307 ms
53,088 KB
testcase_01 AC 313 ms
53,052 KB
testcase_02 AC 317 ms
53,640 KB
testcase_03 AC 314 ms
53,060 KB
testcase_04 AC 316 ms
53,048 KB
testcase_05 AC 503 ms
60,664 KB
testcase_06 AC 405 ms
56,240 KB
testcase_07 AC 497 ms
59,028 KB
testcase_08 AC 322 ms
53,148 KB
testcase_09 AC 335 ms
53,260 KB
testcase_10 AC 579 ms
61,052 KB
testcase_11 AC 564 ms
60,956 KB
testcase_12 AC 880 ms
61,720 KB
testcase_13 AC 327 ms
53,336 KB
testcase_14 AC 332 ms
53,296 KB
testcase_15 AC 309 ms
53,372 KB
testcase_16 AC 307 ms
52,860 KB
testcase_17 AC 309 ms
53,340 KB
testcase_18 AC 579 ms
59,500 KB
testcase_19 AC 564 ms
59,364 KB
testcase_20 AC 698 ms
61,448 KB
testcase_21 AC 653 ms
59,468 KB
testcase_22 AC 667 ms
60,596 KB
testcase_23 AC 542 ms
59,696 KB
testcase_24 AC 652 ms
59,460 KB
testcase_25 AC 531 ms
59,264 KB
testcase_26 AC 533 ms
60,548 KB
testcase_27 AC 664 ms
61,416 KB
testcase_28 AC 559 ms
60,708 KB
testcase_29 AC 682 ms
61,584 KB
testcase_30 AC 523 ms
61,264 KB
testcase_31 AC 677 ms
62,100 KB
testcase_32 AC 540 ms
61,824 KB
testcase_33 AC 708 ms
61,432 KB
testcase_34 AC 547 ms
61,716 KB
testcase_35 AC 722 ms
61,404 KB
testcase_36 AC 315 ms
53,252 KB
testcase_37 AC 320 ms
52,952 KB
testcase_38 AC 315 ms
53,168 KB
testcase_39 AC 310 ms
53,120 KB
testcase_40 AC 319 ms
53,056 KB
testcase_41 AC 314 ms
53,232 KB
testcase_42 AC 313 ms
53,160 KB
testcase_43 AC 465 ms
60,172 KB
testcase_44 AC 491 ms
61,544 KB
testcase_45 AC 340 ms
53,212 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.kt:1:10: warning: parameter 'args' is never used
fun main(args: Array<String>) {
         ^
Main.kt:7:39: warning: name shadowed: it
        it.mapIndexedNotNull { index, it ->
                                      ^
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, it ->
            if (it == "#") (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 (tryPaint(cellsList, blackIndices, H, W, vecY, vecX)) {
            println("YES")
            return
        }
    }
    println("NO")
}

fun tryPaint(
    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()) {
            val x = indices[y].removeAt(0)
            val trgY = y + vecY
            val trgX = x + vecX

            //cells[y][x] = "R"

            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