提出 #42941253


ソースコード 拡げる

import kotlin.math.max
import kotlin.math.min

fun main() {
    val (ha, wa) = readLine()!!.split(" ").map { it.toInt() }
    val a = List(ha) {
        readLine()!!
    }.toMutableList()

    val (hb, wb) = readLine()!!.split(" ").map { it.toInt() }
    val b = List(hb) {
        readLine()!!
    }.toMutableList()

    val (hx, wx) = readLine()!!.split(" ").map { it.toInt() }
    val x = List(hx) {
        readLine()!!
    }.toMutableList()

    // 黒範囲の高さ
    var ar = realRange(a)
    var br = realRange(b)
    var xr = realRange(x)

    if(ar.height() > xr.height() || ar.weight() > xr.weight() || br.height() > xr.height() || br.weight() > xr.weight()) {
        println("No")
        return
    }

    // 切り詰め
    for(i in 0 until ar.hStart) {
        a.removeAt(0)
    }
    ar = realRange(a)

    for(i in ar.hEnd + 1 until a.size) {
        a.removeAt(a.size - 1)
    }
    ar = realRange(a)

    for(i in 0 until a.size) {
        val t = a[i].toMutableList()
        for(j in 0 until ar.wStart) {
            t.removeAt(0)
        }
        a[i] = t.joinToString("")
    }
    ar = realRange(a)

    for(i in 0 until a.size) {
        val t = a[i].toMutableList()
        for(j in ar.wEnd + 1 until t.size) {
            t.removeAt(ar.wEnd + 1)
        }
        a[i] = t.joinToString("")
    }
    ar = realRange(a)

    for(i in 0 until xr.hStart) {
        x.removeAt(0)
    }
    xr = realRange(x)

    for(i in xr.hEnd + 1 until x.size) {
        x.removeAt(x.size - 1)
    }
    xr = realRange(x)

    for(i in 0 until x.size) {
        val t = x[i].toMutableList()
        for(j in 0 until xr.wStart) {
            t.removeAt(0)
        }
        x[i] = t.joinToString("")
    }
    xr = realRange(x)
    for(i in 0 until x.size) {
        val t = x[i].toMutableList()
        for(j in xr.wEnd + 1 until t.size) {
            t.removeAt(xr.wEnd + 1)
        }
        x[i] = t.joinToString("")
    }

    xr = realRange(x)

    for(i in 0 until br.hStart) {
        b.removeAt(0)
    }
    br = realRange(b)

    for(i in br.hEnd + 1 until b.size) {
        b.removeAt(b.size - 1)
    }
    br = realRange(b)

    for(i in 0 until b.size) {
        val t = b[i].toMutableList()
        for(j in 0 until br.wStart) {
            t.removeAt(0)
        }
        b[i] = t.joinToString("")
    }
    br = realRange(b)
    for(i in 0 until b.size) {
        val t = b[i].toMutableList()
        for(j in br.wEnd + 1 until t.size) {
            t.removeAt(br.wEnd + 1)
        }
        b[i] = t.joinToString("")
    }
    br = realRange(b)

    val compX = x.map { it.toCharArray() }.toMutableList()

    for(i in 0 until xr.height() - ar.height() + 1) {
        for(j in 0 until xr.weight() - ar.weight() + 1) {
            val rect = emptyRange(xr.height(), xr.weight())

            for(m in 0 until ar.height()) {
                for(n in 0 until ar.weight()) {
                    val mm = m + i
                    val nn = n + j

                    rect[mm][nn] = a[m][n]
                }
            }
            for(k in 0 until xr.height() - br.height() + 1) {
                for(l in 0 until xr.weight() - br.weight() + 1) {
                    val copyRect = rect.map { it.clone() }.toMutableList()

                    for(m in 0 until br.height()) {
                        for(n in 0 until br.weight()) {
                            val mm = m + k
                            val nn = n + l

                            if(b[m][n] == '#') {
                                copyRect[mm][nn] = b[m][n]
                            }
                        }
                    }

                    if(copyRect.map { it.joinToString("") } == compX.map { it.joinToString("") }) {
                        println("Yes")
                        return
                    }
                }
            }
        }
    }

    println("No")
}

fun emptyRange(h: Int, w: Int): MutableList<CharArray> {
    return MutableList(h) { CharArray(w) { '.' } }
}

fun realRange(s: List<String>): RealRange {
    val hStart = s.indexOfFirst { it.contains('#') }
    val hEnd = s.indexOfLast { it.contains('#') }

    val h = s.size
    val w = s[0].length

    var wStart = Int.MAX_VALUE
    var wEnd = 0
    for(i in 0 until h) {
        if(!s[i].contains('#')) {
            continue
        }

        val start = s[i].indexOf('#')
        val end = s[i].lastIndexOf('#')
        wStart = min(wStart, start)
        wEnd = max(wEnd, end)
    }

    return RealRange(hStart, hEnd, wStart, wEnd)
}

data class RealRange(
    val hStart: Int, val hEnd: Int, val wStart: Int, val wEnd: Int
) {
    fun height(): Int {
        return hEnd - hStart + 1
    }

    fun weight(): Int {
        return wEnd - wStart + 1
    }
}

提出情報

提出日時
問題 C - Ideal Sheet
ユーザ dhirabayashi
言語 Kotlin (1.3.71)
得点 300
コード長 4956 Byte
結果 AC
実行時間 402 ms
メモリ 63844 KiB

コンパイルエラー

warning: ATTENTION!
This build uses unsafe internal compiler arguments:

-XXLanguage:+InlineClasses

This mode is not recommended for production use,
as no stability/compatibility guarantees are given on
compiler or generated code. Use it at your own risk!

Main.kt:5:14: warning: variable 'wa' is never used
    val (ha, wa) = readLine()!!.split(" ").map { it.toInt() }
             ^
Main.kt:10:14: warning: variable 'wb' is never used
    val (hb, wb) = readLine()!!.split(" ").map { it.toInt() }
             ^
Main.kt:15:14: warning: variable 'wx' is never used
    val (hx, wx) = readLine()!!.split(" ").map { it.toInt() }
             ^
Main.kt:164:9: warning: variable 'w' is never used
    val w = s[0].length
        ^

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 300 / 300
結果
AC × 4
AC × 32
セット名 テストケース
Sample example_00.txt, example_01.txt, example_02.txt, example_03.txt
All example_00.txt, example_01.txt, example_02.txt, example_03.txt, hand_00.txt, hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, hand_05.txt, hand_06.txt, hand_07.txt, random2_00.txt, random2_01.txt, random2_02.txt, random2_03.txt, random2_04.txt, random2_05.txt, random2_06.txt, random2_07.txt, random2_08.txt, random2_09.txt, random_00.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt
ケース名 結果 実行時間 メモリ
example_00.txt AC 136 ms 39604 KiB
example_01.txt AC 109 ms 39712 KiB
example_02.txt AC 100 ms 36148 KiB
example_03.txt AC 119 ms 39740 KiB
hand_00.txt AC 122 ms 39888 KiB
hand_01.txt AC 402 ms 62492 KiB
hand_02.txt AC 371 ms 63844 KiB
hand_03.txt AC 356 ms 62068 KiB
hand_04.txt AC 121 ms 39848 KiB
hand_05.txt AC 115 ms 39668 KiB
hand_06.txt AC 112 ms 39700 KiB
hand_07.txt AC 118 ms 39808 KiB
random2_00.txt AC 114 ms 39776 KiB
random2_01.txt AC 126 ms 40036 KiB
random2_02.txt AC 124 ms 39888 KiB
random2_03.txt AC 117 ms 39752 KiB
random2_04.txt AC 103 ms 36080 KiB
random2_05.txt AC 125 ms 39920 KiB
random2_06.txt AC 127 ms 39936 KiB
random2_07.txt AC 130 ms 39948 KiB
random2_08.txt AC 123 ms 39816 KiB
random2_09.txt AC 132 ms 39568 KiB
random_00.txt AC 136 ms 40060 KiB
random_01.txt AC 129 ms 40108 KiB
random_02.txt AC 136 ms 40252 KiB
random_03.txt AC 122 ms 39692 KiB
random_04.txt AC 137 ms 40064 KiB
random_05.txt AC 101 ms 35948 KiB
random_06.txt AC 107 ms 36252 KiB
random_07.txt AC 123 ms 39796 KiB
random_08.txt AC 127 ms 39816 KiB
random_09.txt AC 131 ms 40192 KiB