From f18ae8d14984d7b8ef7456c049b7e88cb77de0ab Mon Sep 17 00:00:00 2001 From: yenru0 Date: Fri, 5 Sep 2025 17:54:40 +0900 Subject: [PATCH] complete 11735.kt 14254.kt 16293.kt --- storage/zeta/kt/completed/11735.kt | 65 ++++++++++++++++++++++++++++++ storage/zeta/kt/completed/14254.kt | 37 +++++++++++++++++ storage/zeta/kt/completed/16293.kt | 40 ++++++++++++++++++ 3 files changed, 142 insertions(+) create mode 100644 storage/zeta/kt/completed/11735.kt create mode 100644 storage/zeta/kt/completed/14254.kt create mode 100644 storage/zeta/kt/completed/16293.kt diff --git a/storage/zeta/kt/completed/11735.kt b/storage/zeta/kt/completed/11735.kt new file mode 100644 index 0000000..e89b82a --- /dev/null +++ b/storage/zeta/kt/completed/11735.kt @@ -0,0 +1,65 @@ +fun 미래예측정산소(n: Long, queries: List>): List { + val isRowed = BooleanArray(n.toInt()) { false } + val isColumned = BooleanArray(n.toInt()) { false } + var rowSum = 0L + var rowCnt = 0L + var columnSum = 0L + var columnCnt = 0L + return queries.map { (selector, index) -> + if (selector == 0) { // row + if (isRowed[index.toInt()]) { + 0 + } else { + isRowed[index.toInt()] = true + + val value = (index + 2) * (n - columnCnt) - columnSum + (n * (n - 1)) / 2 + + rowCnt++ + rowSum += index + value + } + } else { + if (isColumned[index.toInt()]) { + 0 + } else { + isColumned[index.toInt()] = true + + val value = (index + 2) * (n - rowCnt) - rowSum + (n * (n - 1)) / 2 + + columnCnt++ + columnSum += index + value + } + } + } +} + +fun main() = with(System.`in`.bufferedReader()) { + val (n, q) = this.readLine().split(" ").map { it.toInt() } + + val queries = (1..q).map { + val queryLine = this.readLine().split(" ") + val selectorChar = queryLine[0][0] + val selector = when (selectorChar) { + 'R' -> { + 0 + } + + 'C' -> { + 1 + } + + else -> { + -1 + } + } + val value = queryLine[1].toLong() + selector to value - 1 // index value로 변환 + } + + println( + 미래예측정산소(n.toLong(), queries).joinToString("\n") + ) + + +} \ No newline at end of file diff --git a/storage/zeta/kt/completed/14254.kt b/storage/zeta/kt/completed/14254.kt new file mode 100644 index 0000000..a9b6980 --- /dev/null +++ b/storage/zeta/kt/completed/14254.kt @@ -0,0 +1,37 @@ +fun diffStr(s1: String, s2: String) = + (s1.toList() zip s2.toList()).count { it.first != it.second } + +fun 비밀번호변경을위한최소수정횟수(pwdOld: String, k: Int): Int { + val n = pwdOld.length + + if (2 * k <= n) { // <분리> 케이스 + return diffStr(pwdOld.substring(0, k), pwdOld.substring(n - k)) + } else { + var modify = 0 + val space = n - k + for (i in 0 until space) { + var pos = i + val cnts = IntArray(26) { 0 } + + while (pos < n) { + cnts[pwdOld[pos].code - 'a'.code]++ + pos += space + } + + val maxSent = cnts.withIndex().maxBy { it.value } + + modify += cnts.sum() - maxSent.value + } + return modify + } + +} + +fun main() = with(System.`in`.bufferedReader()) { + val pwdOld = this.readLine().trim() + val k = this.readLine().toInt() + + println( + 비밀번호변경을위한최소수정횟수(pwdOld, k) + ) +} \ No newline at end of file diff --git a/storage/zeta/kt/completed/16293.kt b/storage/zeta/kt/completed/16293.kt new file mode 100644 index 0000000..fe876cf --- /dev/null +++ b/storage/zeta/kt/completed/16293.kt @@ -0,0 +1,40 @@ +import kotlin.math.roundToInt + +fun main() = with(System.`in`.bufferedReader()) { + val (h, w) = this.readLine().split(" ").map { it.toInt() } + var s = 0 + var cnt = 0 + var left: Int = 0 + var right: Int = 0 + for (i in h downTo 1) { + val line = this.readLine() + for (j in 0 until w) { + if (line[j] == '.') { + continue + } else { + s += j + cnt++ + } + } + + if (i == 1) { + left = line.withIndex().first { it.value != '.' }.index + right = line.withIndex().last { it.value != '.' }.index + } + } + if (cnt == 0) { + println("balanced") + } else { + val mid = (s.toDouble() / cnt.toDouble()).roundToInt() + + if (mid < left) { + println("left") + } else if (mid > right) { + println("right") + } else { + println("balanced") + } + } + + +} \ No newline at end of file