complete 11735.kt 14254.kt 16293.kt

This commit is contained in:
2025-09-05 17:54:40 +09:00
parent 97b6fb2901
commit f18ae8d149
3 changed files with 142 additions and 0 deletions

View 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")
}
}
}