From 50a9d3a674a4c02b60e22c372618c210c0eee644 Mon Sep 17 00:00:00 2001 From: soopeach Date: Mon, 6 Nov 2023 18:20:18 +0900 Subject: [PATCH 1/4] =?UTF-8?q?Feat:=20=EB=85=B8=EB=93=9C=EC=82=AC?= =?UTF-8?q?=EC=9D=B4=EC=9D=98=20=EA=B1=B0=EB=A6=AC=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...4\354\235\230 \352\261\260\353\246\254.kt" | 84 +++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 "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" 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 From f04f2d93a0a8952cccb4487f3b4fe3707b18458a Mon Sep 17 00:00:00 2001 From: soopeach Date: Sun, 12 Nov 2023 02:52:13 +0900 Subject: [PATCH 2/4] =?UTF-8?q?Feat:=20=EB=B9=97=EB=AC=BC=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../49week/\353\271\227\353\254\274.kt" | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 "src/main/kotlin/hyunsoo/49week/\353\271\227\353\254\274.kt" 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 From 5b0efb24f38d8d36fc29c9fc7254076595dedf3d Mon Sep 17 00:00:00 2001 From: soopeach Date: Sun, 12 Nov 2023 11:17:19 +0900 Subject: [PATCH 3/4] =?UTF-8?q?Feat:=20=EB=B2=BC=EB=9D=BD=EC=B9=98?= =?UTF-8?q?=EA=B8=B0=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...74\353\235\275\354\271\230\352\270\260.kt" | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 "src/main/kotlin/hyunsoo/49week/\353\262\274\353\235\275\354\271\230\352\270\260.kt" 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 From 2e0432ee9468a4b1d5704e6ba04b333328b985b4 Mon Sep 17 00:00:00 2001 From: soopeach Date: Sun, 12 Nov 2023 16:54:15 +0900 Subject: [PATCH 4/4] =?UTF-8?q?Feat:=20=ED=95=A0=EC=9D=B8=20=ED=96=89?= =?UTF-8?q?=EC=82=AC=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...0\354\235\270 \355\226\211\354\202\254.kt" | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 "src/main/kotlin/hyunsoo/49week/\355\225\240\354\235\270 \355\226\211\354\202\254.kt" 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