From 1c2acfaebefdb4dcbe3e7476946b844aa21fd22e Mon Sep 17 00:00:00 2001 From: yenru0 Date: Wed, 9 Jul 2025 16:23:59 +0900 Subject: [PATCH] complete 11399.kt 16438.kt 25571.kt --- storage/zeta/kt/completed/11399.kt | 14 ++++++ storage/zeta/kt/completed/16438.kt | 41 ++++++++++++++++ storage/zeta/kt/completed/25571.kt | 77 ++++++++++++++++++++++++++++++ 3 files changed, 132 insertions(+) create mode 100644 storage/zeta/kt/completed/11399.kt create mode 100644 storage/zeta/kt/completed/16438.kt create mode 100644 storage/zeta/kt/completed/25571.kt diff --git a/storage/zeta/kt/completed/11399.kt b/storage/zeta/kt/completed/11399.kt new file mode 100644 index 0000000..ec8950a --- /dev/null +++ b/storage/zeta/kt/completed/11399.kt @@ -0,0 +1,14 @@ +fun minimumTimeTaken(times: List): Int { + var total = 0; + return times.sorted().sumOf { + total += it + total + } +} + + +fun main() = with(System.`in`.bufferedReader()) { + readLine() + val times = this.readLine().split(' ').map { it.toInt() } + println(minimumTimeTaken(times)) +} \ No newline at end of file diff --git a/storage/zeta/kt/completed/16438.kt b/storage/zeta/kt/completed/16438.kt new file mode 100644 index 0000000..21b6c6a --- /dev/null +++ b/storage/zeta/kt/completed/16438.kt @@ -0,0 +1,41 @@ +fun cluster(schedule: Array>, depth: Int, lo: Int, hi: Int) { + if (hi - lo <= 1) { + return + } + val mid = (lo + hi) / 2 + for (i in lo until mid) { + schedule[depth][i] = false + } + for (i in mid until hi) { + schedule[depth][i] = true + } + cluster(schedule, depth + 1, lo, mid) + cluster(schedule, depth + 1, mid, hi) +} + +fun getWeeklySchedule(n: Int): Array> { + val schedule = Array(7, { i -> + Array(n, { j -> + if (j == 0) { + true + } else { + false + } + }) + }) + cluster(schedule, 0, 0, n) + return schedule +} + +fun main() { + println( + getWeeklySchedule(readln().toInt()).joinToString(separator = "\n") { i -> + i.joinToString(separator = "") { + if (it) { + "B" + } else { + "A" + } + } + }) +} \ No newline at end of file diff --git a/storage/zeta/kt/completed/25571.kt b/storage/zeta/kt/completed/25571.kt new file mode 100644 index 0000000..7b547bb --- /dev/null +++ b/storage/zeta/kt/completed/25571.kt @@ -0,0 +1,77 @@ +enum class VarEdge() { + DECREASING, + STATIC, + INCREASING; + + companion object { + fun getEdgeFrom(before: Int, ahead: Int): VarEdge { + return if (before - ahead > 0) { + DECREASING + } else if (before - ahead == 0) { + STATIC + } else { + INCREASING + } + } + } + +} + + +fun getCountZigzagSubarray(arr: List): Long { + + val arrEdges = arr.slice(0 until arr.size - 1).zip(arr.slice(1 until arr.size)).map { (before, ahead) -> + VarEdge.getEdgeFrom(before, ahead) + } + val intervals: MutableList> = mutableListOf() + + var last = -1 + var beforeEdge = VarEdge.STATIC + + arrEdges.withIndex().forEach { (index, edge) -> + if (edge == VarEdge.DECREASING) { + if (beforeEdge == VarEdge.INCREASING) { + + } else if (beforeEdge == VarEdge.STATIC) { + last = index + } else { + intervals.add(Pair(last, index)) + last = index + } + } else if (edge == VarEdge.INCREASING) { + if (beforeEdge == VarEdge.DECREASING) { + + } else if (beforeEdge == VarEdge.STATIC) { + last = index + } else { + intervals.add(Pair(last, index)) + last = index + } + } else { + if (beforeEdge != VarEdge.STATIC) { + intervals.add(Pair(last, index)) + last = index + } + } + + beforeEdge = edge + } + if (beforeEdge != VarEdge.STATIC) { + intervals.add(Pair(last, arr.size - 1)) + } + + return intervals.sumOf { + val n = (it.second - it.first).toLong() + (n) * (n + 1) / 2 + } +} + + +fun main() = with(System.`in`.bufferedReader()) { + val t = this.readLine().toInt() + repeat(t) { + this.readLine() + val arr = this.readLine().split(' ').map { it.toInt() } + println(getCountZigzagSubarray(arr)) + } +} \ No newline at end of file