Submission #54341716


Source Code Expand

import MutableIntMap.Companion.mutableIntMapOf
import java.io.*
import java.util.*
import kotlin.collections.*
import kotlin.math.*

val INPUT: InputStream = System.`in`
val OUTPUT: PrintStream = System.out

val _reader = INPUT.bufferedReader()

var _tokenizer: StringTokenizer = StringTokenizer("")
fun read(): String {
    while (!_tokenizer.hasMoreTokens()) {
        _tokenizer = StringTokenizer(_reader.readLine() ?: return "", " ")
    }
    return _tokenizer.nextToken()
}

fun readInt() = read().toInt()
fun readDouble() = read().toDouble()
fun readLong() = read().toLong()
fun readStrings(n: Int) = List(n) { read() }
fun readInts(n: Int) = List(n) { readInt() }
fun readIntArray(n: Int) = IntArray(n) { readInt() }
fun readDoubles(n: Int) = List(n) { readDouble() }
fun readDoubleArray(n: Int) = DoubleArray(n) { readDouble() }
fun readLongs(n: Int) = List(n) { readLong() }
fun readLongArray(n: Int) = LongArray(n) { readLong() }

val _writer = PrintWriter(OUTPUT, false)
inline fun output(block: PrintWriter.() -> Unit) {
    _writer.apply(block).flush()
}

class MutableIntMap<K> : LinkedHashMap<K, Int>() {
    override operator fun get(key: K): Int = super.get(key) ?: 0

    fun increment(key: K, value: Int = 1) {
        this[key] = this[key] + value
    }

    companion object {
        fun <K> mutableIntMapOf(vararg pairs: Pair<K, Int>) =
            MutableIntMap<K>().apply { putAll(pairs) }
    }
}

typealias Pii = Pair<Int, Int>

fun readPii() = readInt() to readInt()
fun readPiis(n: Int) = List(n) { readPii() }

infix fun Int.hasBit(i: Int): Boolean = this and (1 shl i) > 0
infix fun Int.xorBit(i: Int): Int = this xor (1 shl i)
infix fun Long.hasBit(i: Int): Boolean = this and (1L shl i) > 0
infix fun Long.xorBit(i: Int): Long = this xor (1L shl i)

fun largerStackSize(stackSizeMegaBytes: Int = 100, action: () -> Unit) {
    Thread(null, action, "", 1024L * 1024 * stackSizeMegaBytes).apply {
        start()
        join()
    }
}

// #################################################################################################

fun dfs(n: Int): List<String> {
    if (n == 0) return listOf("#")
    val s = dfs(n - 1)
    val m = s.size
    val ans = List(m * 3) { CharArray(m * 3) { '.' } }
    for (a in 0 until 3) {
        for (b in 0 until 3) {
            if (a == 1 && b == 1) continue
            for (i in 0 until m) for (j in 0 until m) ans[m * a + i][m * b + j] = s[i][j]
        }
    }
    return ans.map { it.concatToString() }
}

fun solve() {
    val n = readInt()
    val s = dfs(n)
    output {
        for (i in s) println(i)
    }
}

fun main() {
//    repeat(readInt()) { solve() }
    solve()
}

Submission Info

Submission Time
Task C - Sierpinski carpet
User wangchaohui
Language Kotlin (Kotlin/JVM 1.8.20)
Score 250
Code Size 2753 Byte
Status AC
Exec Time 113 ms
Memory 43384 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 250 / 250
Status
AC × 2
AC × 9
Set Name Test Cases
Sample example_00.txt, example_01.txt
All example_00.txt, example_01.txt, test_00.txt, test_01.txt, test_02.txt, test_03.txt, test_04.txt, test_05.txt, test_06.txt
Case Name Status Exec Time Memory
example_00.txt AC 59 ms 39956 KiB
example_01.txt AC 61 ms 40024 KiB
test_00.txt AC 91 ms 41656 KiB
test_01.txt AC 61 ms 40172 KiB
test_02.txt AC 66 ms 40168 KiB
test_03.txt AC 54 ms 38844 KiB
test_04.txt AC 63 ms 40160 KiB
test_05.txt AC 113 ms 43384 KiB
test_06.txt AC 63 ms 40028 KiB