import kotlin.random.Random import kotlin.system.exitProcess val br = System.`in`.bufferedReader() fun readLine(): String? = br.readLine() fun readString() = readLine()!! fun readStrings() = readLine()?.split(" ")?.filter { it.isNotEmpty() } ?: listOf() fun readInts() = readStrings().map { it.toInt() }.toIntArray() const val MAX_STACK_SIZE: Long = 128 * 1024 * 1024 fun main() { val thread = Thread(null, ::run, "solve", MAX_STACK_SIZE) thread.setUncaughtExceptionHandler { _, e -> e.printStackTrace(); exitProcess(1) } thread.start() } fun run() { val (H, W) = readInts() val S = Array(H) { readString().toCharArray() } output(solve(H, W, S)) } fun solve(H: Int, W: Int, S: Array): Array { while (true) { val r = Random.nextInt(H) val c = Random.nextInt(W) if (S[r][c] == '*') continue var sameCol = 0 for (r0 in 0 until H) { if (S[r0][c] == '*') sameCol++ } if (sameCol > 1) continue var sameRow = 0 for (c0 in 0 until W) { if (S[r][c0] == '*') sameRow++ } if (sameRow > 1) continue var sameDiag = 0 var r0 = r var c0 = c while (r0 >= 0 && c0 >= 0) { if (S[r0][c0] == '*') sameDiag++ r0-- c0-- } r0 = r c0 = c while (r0 < H && c0 < W) { if (S[r0][c0] == '*') sameDiag++ r0++ c0++ } if (sameDiag > 1) continue sameDiag = 0 r0 = r c0 = c while (r0 >= 0 && c0 < W) { if (S[r0][c0] == '*') sameDiag++ r0-- c0++ } r0 = r c0 = c while (r0 < H && c0 >= 0) { if (S[r0][c0] == '*') sameDiag++ r0++ c0-- } if (sameDiag > 1) continue S[r][c] = '*' return S } } fun output(res: Array) = res.joinToString("\n") { it.joinToString("") } .apply { println(this) }