結果

問題 No.179 塗り分け
ユーザー komkomhkomkomh
提出日時 2019-04-25 17:12:16
言語 Kotlin
(1.9.10)
結果
WA  
実行時間 -
コード長 1,430 bytes
コンパイル時間 15,085 ms
コンパイル使用メモリ 424,152 KB
実行使用メモリ 63,060 KB
最終ジャッジ日時 2023-08-13 01:51:37
合計ジャッジ時間 23,256 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 322 ms
60,568 KB
testcase_01 AC 301 ms
52,980 KB
testcase_02 AC 569 ms
62,832 KB
testcase_03 WA -
testcase_04 AC 735 ms
63,060 KB
testcase_05 AC 311 ms
53,128 KB
testcase_06 TLE -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

package yukicoder

fun main() {
    val (h, w) = readLine()!!.split(" ").map(String::toInt)
    val blacks = (0 until h).flatMap { h2 ->
        readLine()!!
            .mapIndexed { index, c -> Pair(index, c) }
            .filter { it.second != '.' }
            .map { Pair(h2, it.first) }
    }

//    blacks.forEach { println(it) }
//    println("----------")

    if (blacks.size % 2 != 0) {
        println("NO")
        return
    }

    val redSize = blacks.size / 2
    fun canPaint(vararg redIndexes: Int): Boolean {
        return when (redIndexes.size >= redSize) {
            true -> {
                val redMasus = redIndexes.map { blacks[it] }
                val blueMasus = blacks.filter { !redMasus.contains(it) }

                for (i in 0 until h) {
                    for (j in 0 until w) {
                        if (i == 0 && j == 0) {
                            continue;
                        }
                        val movedReds = redMasus.map { Pair(it.first + i, it.second + j) }
                        if (movedReds == blueMasus) {
                            return true
                        }
                    }
                }
                return false
            }
            false -> (redIndexes.last() until redSize).map { canPaint(*redIndexes, it) }.any()
        }
    }
    when (canPaint(1)) {
        true -> println("YES")
        false -> println("NO")
    }
}
0