complete 11399.kt 16438.kt 25571.kt
This commit is contained in:
14
storage/zeta/kt/completed/11399.kt
Normal file
14
storage/zeta/kt/completed/11399.kt
Normal file
@@ -0,0 +1,14 @@
|
||||
fun minimumTimeTaken(times: List<Int>): 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))
|
||||
}
|
||||
41
storage/zeta/kt/completed/16438.kt
Normal file
41
storage/zeta/kt/completed/16438.kt
Normal file
@@ -0,0 +1,41 @@
|
||||
fun cluster(schedule: Array<Array<Boolean>>, 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<Array<Boolean>> {
|
||||
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"
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
77
storage/zeta/kt/completed/25571.kt
Normal file
77
storage/zeta/kt/completed/25571.kt
Normal file
@@ -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<Int>): 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<Pair<Int, Int>> = 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))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user