complete 11735.kt 14254.kt 16293.kt
This commit is contained in:
65
storage/zeta/kt/completed/11735.kt
Normal file
65
storage/zeta/kt/completed/11735.kt
Normal file
@@ -0,0 +1,65 @@
|
||||
fun 미래예측정산소(n: Long, queries: List<Pair<Int, Long>>): List<Long> {
|
||||
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")
|
||||
)
|
||||
|
||||
|
||||
}
|
||||
37
storage/zeta/kt/completed/14254.kt
Normal file
37
storage/zeta/kt/completed/14254.kt
Normal file
@@ -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)
|
||||
)
|
||||
}
|
||||
40
storage/zeta/kt/completed/16293.kt
Normal file
40
storage/zeta/kt/completed/16293.kt
Normal file
@@ -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")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user