complete 1092.kt 23029.kt 26587.kt 30553.kt
This commit is contained in:
64
storage/zeta/kt/completed/1092.kt
Normal file
64
storage/zeta/kt/completed/1092.kt
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
fun <T : Comparable<T>> List<T>.lowerBound(value: T): Int {
|
||||||
|
var left = 0
|
||||||
|
var right = this.size
|
||||||
|
|
||||||
|
while (left < right) {
|
||||||
|
val mid = (left + right) / 2
|
||||||
|
if (this[mid] < value) {
|
||||||
|
left = mid + 1
|
||||||
|
} else {
|
||||||
|
right = mid
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return left
|
||||||
|
}
|
||||||
|
|
||||||
|
fun minimumPortTime(weightLimits: List<Int> /* sorted */, weights: List<Int>): Int? {
|
||||||
|
|
||||||
|
val weightsCntCategorized = IntArray(weightLimits.size + 1)
|
||||||
|
|
||||||
|
|
||||||
|
weights.forEach {
|
||||||
|
val cat = weightLimits.lowerBound(it)
|
||||||
|
weightsCntCategorized[cat]++
|
||||||
|
}
|
||||||
|
|
||||||
|
if (weightsCntCategorized.last() > 0) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
var time = 0
|
||||||
|
while (true) {
|
||||||
|
repeat(weightLimits.size) {
|
||||||
|
for (i in (0..it).reversed()) {
|
||||||
|
if (weightsCntCategorized[i] == 0) {
|
||||||
|
continue
|
||||||
|
} else {
|
||||||
|
weightsCntCategorized[i]--
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
time++
|
||||||
|
if (weightsCntCategorized.all { it == 0 }) {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return time
|
||||||
|
}
|
||||||
|
|
||||||
|
fun main() = with(System.`in`.bufferedReader()) {
|
||||||
|
this.readLine()
|
||||||
|
|
||||||
|
val weightLimits = this.readLine().split(' ').map { it.toInt() }.sorted()
|
||||||
|
this.readLine()
|
||||||
|
|
||||||
|
val weights = this.readLine().split(' ').map { it.toInt() }
|
||||||
|
|
||||||
|
println(
|
||||||
|
minimumPortTime(weightLimits, weights) ?: -1
|
||||||
|
)
|
||||||
|
}
|
||||||
36
storage/zeta/kt/completed/23029.kt
Normal file
36
storage/zeta/kt/completed/23029.kt
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
fun maxFoodEaten(cntsFoods: List<Int>): Int {
|
||||||
|
val dp = Array(cntsFoods.size) { Array<Int>(3) { 0 } }
|
||||||
|
|
||||||
|
// 0: 안먹을경우
|
||||||
|
// 1: 첫번째인경우
|
||||||
|
// 2: 두번째인경우
|
||||||
|
|
||||||
|
for ((i, food) in cntsFoods.withIndex()) {
|
||||||
|
if (i == 0) {
|
||||||
|
dp[i][1] = food
|
||||||
|
dp[i][2] = 0
|
||||||
|
dp[i][0] = 0
|
||||||
|
} else if (i == 1) {
|
||||||
|
dp[i][2] = dp[i - 1][1] + food / 2
|
||||||
|
dp[i][1] = dp[i - 1][0] + food
|
||||||
|
dp[i][0] = dp[i - 1].max()
|
||||||
|
} else {
|
||||||
|
dp[i][0] = dp[i - 1].max()
|
||||||
|
dp[i][1] = dp[i - 1][0] + food
|
||||||
|
dp[i][2] = dp[i - 1][1] + food / 2
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return dp.last().max()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun main() = with(System.`in`.bufferedReader()) {
|
||||||
|
val n = this.readLine().toInt()
|
||||||
|
val cntsFoods = (1..n).map {
|
||||||
|
this.readLine().toInt()
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
println(maxFoodEaten(cntsFoods))
|
||||||
|
}
|
||||||
11
storage/zeta/kt/completed/26587.kt
Normal file
11
storage/zeta/kt/completed/26587.kt
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
fun main() = with(System.`in`.bufferedReader()) {
|
||||||
|
this.readLines().map {
|
||||||
|
val words = it.split(' ').toMutableList()
|
||||||
|
val vowelStarts =
|
||||||
|
words.withIndex().filter { it.value.first().lowercaseChar() in listOf('a', 'e', 'i', 'o', 'u') }
|
||||||
|
(vowelStarts zip vowelStarts.reversed()).forEach { (a, b) ->
|
||||||
|
words[a.index] = b.value
|
||||||
|
}
|
||||||
|
words.joinToString(" ")
|
||||||
|
}.forEach(::println)
|
||||||
|
}
|
||||||
47
storage/zeta/kt/completed/30553.kt
Normal file
47
storage/zeta/kt/completed/30553.kt
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
fun main() = with(System.`in`.bufferedReader()) {
|
||||||
|
val (n, m, q) = this.readLine()!!.split(' ').map { it.toInt() }
|
||||||
|
|
||||||
|
val characters = (1..n).map { IntArray(m) }
|
||||||
|
|
||||||
|
repeat(n) {
|
||||||
|
val trait = this.readLine()!!
|
||||||
|
|
||||||
|
for (i in 0 until m) {
|
||||||
|
characters[it][i] = when (trait[i]) {
|
||||||
|
'Y' -> 2
|
||||||
|
'N' -> 1
|
||||||
|
else -> 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
val queries = IntArray(m)
|
||||||
|
|
||||||
|
repeat(q) {
|
||||||
|
val iter = this.readLine()!!.split(' ').iterator()
|
||||||
|
val index = iter.next().toInt() - 1
|
||||||
|
queries[index] = when (iter.next().first()) {
|
||||||
|
'Y' -> 2
|
||||||
|
'N' -> 1
|
||||||
|
else -> 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
val filtered = characters.withIndex().filter { (ind, it) ->
|
||||||
|
(it zip queries).map {
|
||||||
|
if (it.second == 0) {
|
||||||
|
true
|
||||||
|
} else {
|
||||||
|
it.first == it.second
|
||||||
|
}
|
||||||
|
}.all { it }
|
||||||
|
}
|
||||||
|
|
||||||
|
if (filtered.size == 1) {
|
||||||
|
println("unique")
|
||||||
|
println(filtered.first().index + 1)
|
||||||
|
} else {
|
||||||
|
println("ambiguous")
|
||||||
|
println(filtered.size)
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user