From 88a4a1fa08a1091f92ac7864739474918525c876 Mon Sep 17 00:00:00 2001 From: soopeach Date: Tue, 3 Oct 2023 18:17:20 +0900 Subject: [PATCH 1/4] =?UTF-8?q?Feat:=20=EC=95=8C=EA=B3=A0=EC=8A=A4?= =?UTF-8?q?=ED=8C=9F=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...14\352\263\240\354\212\244\355\214\237.kt" | 89 +++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 "src/main/kotlin/hyunsoo/47week/\354\225\214\352\263\240\354\212\244\355\214\237.kt" diff --git "a/src/main/kotlin/hyunsoo/47week/\354\225\214\352\263\240\354\212\244\355\214\237.kt" "b/src/main/kotlin/hyunsoo/47week/\354\225\214\352\263\240\354\212\244\355\214\237.kt" new file mode 100644 index 00000000..32f0df8a --- /dev/null +++ "b/src/main/kotlin/hyunsoo/47week/\354\225\214\352\263\240\354\212\244\355\214\237.kt" @@ -0,0 +1,89 @@ +package hyunsoo.`47week` + +/** + * + * <문제> + * [알고스팟](https://www.acmicpc.net/problem/1261) + * + * - 아이디어 + * + * - 트러블 슈팅 + * + */ +class `전현수_알고스팟` { + + private data class Position(val x: Int, val y: Int) + + private data class Bundle(val pos: Position, val cost: Int) { + constructor(x: Int, y: Int, cost: Int) : this(Position(x, y), cost) + } + + private val dirs = listOf( + Position(1, 0), + Position(0, 1), + Position(-1, 0), + Position(0, -1), + ) + + fun solution() { + + val deque = ArrayDeque() + + val (width, height) = readln().split(" ").map { it.toInt() } + + val map = Array(height) { + readln().chunked(1).map { + if (it == "1") WALL else it.toInt() + }.toIntArray() + + } + + val visited = Array(height) { + BooleanArray(width) + } + + deque.add(Bundle(0, 0, 0)) + visited[0][0] = true + + while (deque.isNotEmpty()) { + + val (pos, cost) = deque.removeFirst() + + map[pos.x][pos.y] = cost + dirs.forEach { dir -> + + val nx = pos.x + dir.x + val ny = pos.y + dir.y + + if (nx !in 0 until height || + ny !in 0 until width || + visited[nx][ny] + ) return@forEach + + visited[nx][ny] = true + + when (map[nx][ny]) { + WALL -> { + deque.addLast(Bundle(nx, ny, cost + 1)) + } + + EMPTY -> { + deque.addFirst(Bundle(nx, ny, cost)) + } + } + } + + } + + println(map[height - 1][width - 1]) + } + + companion object { + const val EMPTY = 0 + const val WALL = -1 + } +} + +fun main() { + 전현수_알고스팟().solution() +} \ No newline at end of file From d5dca069af9f5a38d07e10b6c3e63cff064a6d71 Mon Sep 17 00:00:00 2001 From: soopeach Date: Thu, 5 Oct 2023 10:04:33 +0900 Subject: [PATCH 2/4] =?UTF-8?q?Feat:=20A=EC=99=80=20B=202=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 --- .../hyunsoo/47week/A\354\231\200 B 2.kt" | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 "src/main/kotlin/hyunsoo/47week/A\354\231\200 B 2.kt" diff --git "a/src/main/kotlin/hyunsoo/47week/A\354\231\200 B 2.kt" "b/src/main/kotlin/hyunsoo/47week/A\354\231\200 B 2.kt" new file mode 100644 index 00000000..99a67e79 --- /dev/null +++ "b/src/main/kotlin/hyunsoo/47week/A\354\231\200 B 2.kt" @@ -0,0 +1,51 @@ +package hyunsoo.`47week` + +import kotlin.system.exitProcess + +/** + * + * <문제> + * [A와 B 2](https://www.acmicpc.net/problem/12919) + * + * - 아이디어 + * + * - 트러블 슈팅 + * + */ +class `전현수_A와_B_2` { + + fun solution() { + + val s = readln() + val t = readln() + + find(s, t) + + println(0) + } + + fun find(s: String, t: String) { + + if (s.length == t.length) { + + if (s == t) { + println(1) + exitProcess(0) + } + + return + } + + if (t.last() == 'A') { + find(s, t.substring(0, t.lastIndex)) + } + if (t.first() == 'B') { + find(s, t.substring(1, t.lastIndex + 1).reversed()) + } + + } +} + +fun main() { + 전현수_A와_B_2().solution() +} \ No newline at end of file From 5e6a4bf6609062488dcaeb1eebde590867e2059e Mon Sep 17 00:00:00 2001 From: soopeach Date: Thu, 5 Oct 2023 18:42:26 +0900 Subject: [PATCH 3/4] =?UTF-8?q?Feat:=20=EC=9E=85=EA=B5=AD=EC=8B=AC?= =?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 --- ...05\352\265\255\354\213\254\354\202\254.kt" | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 "src/main/kotlin/hyunsoo/47week/\354\236\205\352\265\255\354\213\254\354\202\254.kt" diff --git "a/src/main/kotlin/hyunsoo/47week/\354\236\205\352\265\255\354\213\254\354\202\254.kt" "b/src/main/kotlin/hyunsoo/47week/\354\236\205\352\265\255\354\213\254\354\202\254.kt" new file mode 100644 index 00000000..a84f3d44 --- /dev/null +++ "b/src/main/kotlin/hyunsoo/47week/\354\236\205\352\265\255\354\213\254\354\202\254.kt" @@ -0,0 +1,52 @@ +package hyunsoo.`47week` + +/** + * + * <문제> + * [입국심사](https://school.programmers.co.kr/learn/courses/30/lessons/43238) + * + * - 아이디어 + * + * - 트러블 슈팅 + * + */ +class `전현수_입국심사` { + + fun solution(n: Int, times: IntArray): Long { + + val sortedTimes = times.sortedBy { it } + + var answer: Long = 0 + + var left = sortedTimes.first().toLong() + var right = sortedTimes.last().toLong() * n + + while (left <= right) { + + val mid = (left + right) / 2 + var people: Long = 0 + + sortedTimes.forEach { time -> + people += mid / time + } + + if (n <= people) { + answer = mid + right = mid - 1 + } else { + left = mid + 1 + } + + } + + return answer + } +} + +fun main() { + 전현수_입국심사() + .solution(6, intArrayOf(7, 10)) + .apply { + println(this) + } +} \ No newline at end of file From 250ab9a9b418dfe5714b5d44f5f04cbf1c78c368 Mon Sep 17 00:00:00 2001 From: soopeach Date: Fri, 6 Oct 2023 15:01:49 +0900 Subject: [PATCH 4/4] =?UTF-8?q?Feat:=20=ED=9A=8C=EC=9E=A5=EB=BD=91?= =?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 --- ...14\354\236\245\353\275\221\352\270\260.kt" | 82 +++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 "src/main/kotlin/hyunsoo/47week/\355\232\214\354\236\245\353\275\221\352\270\260.kt" diff --git "a/src/main/kotlin/hyunsoo/47week/\355\232\214\354\236\245\353\275\221\352\270\260.kt" "b/src/main/kotlin/hyunsoo/47week/\355\232\214\354\236\245\353\275\221\352\270\260.kt" new file mode 100644 index 00000000..146efdf3 --- /dev/null +++ "b/src/main/kotlin/hyunsoo/47week/\355\232\214\354\236\245\353\275\221\352\270\260.kt" @@ -0,0 +1,82 @@ +package hyunsoo.`47week` + +import java.util.* + +/** + * + * <문제> + * [회장뽑기](https://www.acmicpc.net/problem/2660) + * + * - 아이디어 + * + * - 트러블 슈팅 + * + */ +class `전현수_회장뽑기` { + + fun solution() { + + val peopleCnt = readln().toInt() + + val graph = Array(peopleCnt + 1) { + mutableListOf() + } + + val scoreList = IntArray(peopleCnt + 1) + + while (true) { + + val (a, b) = readln().split(" ").map { it.toInt() } + if (a == -1 && b == -1) break + + graph[a].add(b) + graph[b].add(a) + + } + + for (myIndex in 1..peopleCnt) { + val visited = BooleanArray(peopleCnt + 1).apply { + this[0] = true + this[myIndex] = true + } + val queue: Queue> = LinkedList() + + queue.addAll(graph[myIndex] to 1) + + + while (queue.isNotEmpty()) { + + val (friendIndex, cost) = queue.poll() + + if (visited[friendIndex]) continue + + scoreList[myIndex] = cost + visited[friendIndex] = true + + queue.addAll( + graph[friendIndex].filter { visited[it].not() } as MutableList to cost + 1) + + } + } + + val candidateScore = scoreList.drop(1).minOf { it } + println("$candidateScore ${scoreList.count { it == candidateScore }}") + scoreList.forEachIndexed { index, score -> + if (score == candidateScore) print("$index ") + } + + } + + private fun Queue>.addAll( + pairElement: Pair, Int>, + ) { + pairElement.first.forEach { + this.add(it to pairElement.second) + } + } + +} + +fun main() { + 전현수_회장뽑기().solution() +} \ No newline at end of file