diff --git "a/src/main/kotlin/hyunsoo/49week/\353\205\270\353\223\234\354\202\254\354\235\264\354\235\230 \352\261\260\353\246\254.kt" "b/src/main/kotlin/hyunsoo/49week/\353\205\270\353\223\234\354\202\254\354\235\264\354\235\230 \352\261\260\353\246\254.kt" new file mode 100644 index 00000000..cf6c4d45 --- /dev/null +++ "b/src/main/kotlin/hyunsoo/49week/\353\205\270\353\223\234\354\202\254\354\235\264\354\235\230 \352\261\260\353\246\254.kt" @@ -0,0 +1,84 @@ +package hyunsoo.`49week` + +import java.util.* + +/** + * + * <문제> + * [노드사이의 거리](https://www.acmicpc.net/problem/1240) + * + * - 아이디어 + * + * - 트러블 슈팅 + * + */ +class `전현수_노드사이의_거리` { + + private data class Bundle(val node: Int, val cost: Int) + + private lateinit var treeInfo: Array + + fun solution() { + + val (nodeCnt, wantToKnowCnt) = readln().split(" ").map { it.toInt() } + + treeInfo = Array(nodeCnt + 1) { + IntArray(nodeCnt + 1) + } + + repeat(nodeCnt - 1) { + val (start, end, cost) = readln().split(" ").map { it.toInt() } + treeInfo[start][end] = cost + treeInfo[end][start] = cost + } + + repeat(wantToKnowCnt) { + + val (start, end) = readln().split(" ").map { it.toInt() } + + val visited = BooleanArray(nodeCnt + 1) + + val queue: Queue = LinkedList() + + treeInfo[start].forEachIndexed { nodeIndex, cost -> + + if (cost == NO_WAY) return@forEachIndexed + + visited[nodeIndex] = true + queue.add(Bundle(nodeIndex, cost)) + + } + + while (queue.isNotEmpty()) { + + val (node, preCost) = queue.poll() + + if (node == end) { + println(preCost) + return@repeat + } + + treeInfo[node].forEachIndexed { nodeIndex, cost -> + + if (cost == NO_WAY) return@forEachIndexed + + if (visited[nodeIndex]) return@forEachIndexed + + visited[nodeIndex] = true + queue.add(Bundle(nodeIndex, preCost + cost)) + + } + + } + + } + } + + companion object { + const val NO_WAY = 0 + } +} + +fun main() { + 전현수_노드사이의_거리().solution() +} \ No newline at end of file diff --git "a/src/main/kotlin/hyunsoo/49week/\353\262\274\353\235\275\354\271\230\352\270\260.kt" "b/src/main/kotlin/hyunsoo/49week/\353\262\274\353\235\275\354\271\230\352\270\260.kt" new file mode 100644 index 00000000..d00b6ffd --- /dev/null +++ "b/src/main/kotlin/hyunsoo/49week/\353\262\274\353\235\275\354\271\230\352\270\260.kt" @@ -0,0 +1,59 @@ +package hyunsoo.`49week` + +import kotlin.math.max + +/** + * + * <문제> + * [벼락치기](https://www.acmicpc.net/problem/14728) + * + * - 아이디어 + * + * - 트러블 슈팅 + * + */ +class `전현수_벼락치기` { + + private data class Question(val expectedTime: Int, val score: Int) + + fun solution() { + + val (unitCnt, totalTime) = readln().split(" ").map { it.toInt() } + + val questionList = mutableListOf().apply { + add(Question(0, 0)) + } + + repeat(unitCnt) { + + val (expectedTime, score) = readln().split(" ").map { it.toInt() } + questionList.add(Question(expectedTime, score)) + + } + + val dp = Array(unitCnt + 1) { + IntArray(totalTime + 1) + } + for (i in 1..unitCnt) { + val curQuestion = questionList[i] + for (j in 0..totalTime) { + if (curQuestion.expectedTime <= j) { + dp[i][j] = max( + dp[i - 1][j], + dp[i - 1][j - curQuestion.expectedTime] + curQuestion.score + ) + } else { + dp[i][j] = dp[i - 1][j] + } + } + } + + println(dp[unitCnt][totalTime]) + + + } +} + +fun main() { + 전현수_벼락치기().solution() +} \ No newline at end of file diff --git "a/src/main/kotlin/hyunsoo/49week/\353\271\227\353\254\274.kt" "b/src/main/kotlin/hyunsoo/49week/\353\271\227\353\254\274.kt" new file mode 100644 index 00000000..92d28699 --- /dev/null +++ "b/src/main/kotlin/hyunsoo/49week/\353\271\227\353\254\274.kt" @@ -0,0 +1,41 @@ +package hyunsoo.`49week` + +import java.util.* +import kotlin.math.min + +/** + * + * <문제> + * [빗물](https://www.acmicpc.net/problem/14719) + * + * - 아이디어 + * + * - 트러블 슈팅 + * + */ +class `전현수_빗물` { + + fun solution() { + + val (h, w) = readln().split(" ").map { it.toInt() } + val heightInfo = readln().split(" ").map { it.toInt() } + var amount = 0 + + for (i in 1 until w) { + + val leftMax = heightInfo.subList(i, heightInfo.size).maxOf { it } + val rightMax = heightInfo.subList(0, i + 1).maxOf { it } + + val minHeight = min(leftMax, rightMax) + + if (heightInfo[i] < minHeight) amount += minHeight - heightInfo[i] + } + + + println(amount) + } +} + +fun main() { + 전현수_빗물().solution() +} \ No newline at end of file diff --git "a/src/main/kotlin/hyunsoo/49week/\355\225\240\354\235\270 \355\226\211\354\202\254.kt" "b/src/main/kotlin/hyunsoo/49week/\355\225\240\354\235\270 \355\226\211\354\202\254.kt" new file mode 100644 index 00000000..faf9a742 --- /dev/null +++ "b/src/main/kotlin/hyunsoo/49week/\355\225\240\354\235\270 \355\226\211\354\202\254.kt" @@ -0,0 +1,63 @@ +package hyunsoo.`49week` + +/** + * + * <문제> + * [할인 행사](https://school.programmers.co.kr/learn/courses/30/lessons/131127) + * + * - 아이디어 + * + * - 트러블 슈팅 + * + */ +class `전현수_할인_행사` { + + fun solution(want: Array, number: IntArray, discount: Array): Int { + + var answer = 0 + + for (i in 0 .. discount.size - 10) { + + val wishList = mutableMapOf() + + want.forEachIndexed { index, item -> + wishList[item] = number[index] + } + + repeat(10) { + val index = i + it + wishList[discount[index]]?.let { pre -> + wishList[discount[index]] = pre - 1 + } + } + if (wishList.values.all { it <= 0 }) answer += 1 + } + + return answer + } +} + +fun main() { + 전현수_할인_행사().solution( + arrayOf("banana", "apple", "rice", "pork", "pot"), + intArrayOf(3, 2, 2, 2, 1), + arrayOf( + "chicken", + "apple", + "apple", + "banana", + "rice", + "apple", + "pork", + "banana", + "pork", + "rice", + "pot", + "banana", + "apple", + "banana" + ) + ).apply { + println(this) + } +} \ No newline at end of file