From 5d06363258f31d8be9a9b889e79691ebe42fa09e Mon Sep 17 00:00:00 2001 From: bngsh Date: Sun, 8 Oct 2023 11:16:18 +0900 Subject: [PATCH 1/4] =?UTF-8?q?solve:=20=EC=95=8C=EA=B3=A0=EC=8A=A4?= =?UTF-8?q?=ED=8C=9F?= 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" | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 "src/main/kotlin/byeonghee/week47/\354\225\214\352\263\240\354\212\244\355\214\237.kt" diff --git "a/src/main/kotlin/byeonghee/week47/\354\225\214\352\263\240\354\212\244\355\214\237.kt" "b/src/main/kotlin/byeonghee/week47/\354\225\214\352\263\240\354\212\244\355\214\237.kt" new file mode 100644 index 00000000..246c2a1a --- /dev/null +++ "b/src/main/kotlin/byeonghee/week47/\354\225\214\352\263\240\354\212\244\355\214\237.kt" @@ -0,0 +1,53 @@ +package byeonghee.week47 + +import java.util.* + +class 소병희_알고스팟 { + + companion object { + const val INF = 99_999 + const val WALL = 1 + const val ROOM = 0 + + val dr = intArrayOf(0, 1, 0, -1) + val dc = intArrayOf(1, 0, -1, 0) + + fun solve() = with(System.`in`.bufferedReader()) { + val (n, m) = readLine().split(" ").map { it.toInt() } + val maze = Array(m) { IntArray(n) } + val dist = Array(m) { IntArray(n) { INF } } + val pq = PriorityQueue { a, b -> a[0] - b[0] } + + repeat(m) { i -> + readLine().forEachIndexed { j, v -> + maze[i][j] = v.digitToInt() + } + } + + pq.add(intArrayOf(0, 0, 0)) + while(pq.isNotEmpty()) { + val (d, r, c) = pq.poll() + if (dist[r][c] <= d) continue + dist[r][c] = d + + for(dir in 0 until 4) { + val nr = r + dr[dir] + val nc = c + dc[dir] + if (nr !in maze.indices || nc !in maze[0].indices) continue + if (maze[nr][nc] == ROOM) { + pq.add(intArrayOf(d, nr, nc)) + } + else if (maze[nr][nc] == WALL) { + pq.add(intArrayOf(d+1, nr, nc)) + } + } + } + + println(dist[m-1][n-1]) + } + } +} + +fun main() { + 소병희_알고스팟.solve() +} \ No newline at end of file From 0a6939435e0fb1252cf608a7a7dd3e8a192eb38d Mon Sep 17 00:00:00 2001 From: bngsh Date: Sun, 8 Oct 2023 11:26:38 +0900 Subject: [PATCH 2/4] =?UTF-8?q?solve:=20A=EC=99=80=20B=202?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../byeonghee/week47/A\354\231\200 B 2.kt" | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 "src/main/kotlin/byeonghee/week47/A\354\231\200 B 2.kt" diff --git "a/src/main/kotlin/byeonghee/week47/A\354\231\200 B 2.kt" "b/src/main/kotlin/byeonghee/week47/A\354\231\200 B 2.kt" new file mode 100644 index 00000000..0eab3943 --- /dev/null +++ "b/src/main/kotlin/byeonghee/week47/A\354\231\200 B 2.kt" @@ -0,0 +1,37 @@ +package byeonghee.week47 + +class 소병희_A와B2 { + + companion object { + fun solve() = with(System.`in`.bufferedReader()) { + val s = readLine() + val t = readLine() + + fun checkAB(sb: StringBuilder): Boolean { + if (s == sb.toString()) return true + if (s.length == sb.length) return false + + if (sb.last() == 'A') { + val nsb = StringBuilder(sb) + nsb.deleteCharAt(nsb.lastIndex) + if (checkAB(nsb)) return true + } + if (sb.first() == 'B') { + val nsb = StringBuilder(sb) + nsb.deleteCharAt(0) + nsb.reverse() + if (checkAB(nsb)) return true + } + + return false + } + + val sb = StringBuilder(t) + println(if (checkAB(sb)) 1 else 0) + } + } +} + +fun main() { + 소병희_A와B2.solve() +} \ No newline at end of file From bf133f27d2c00f97e409af8ad37d9c4d6bdc50d4 Mon Sep 17 00:00:00 2001 From: bngsh Date: Sun, 8 Oct 2023 11:45:37 +0900 Subject: [PATCH 3/4] =?UTF-8?q?solve:=20=ED=9A=8C=EC=9E=A5=EB=BD=91?= =?UTF-8?q?=EA=B8=B0?= 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" | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 "src/main/kotlin/byeonghee/week47/\355\232\214\354\236\245\353\275\221\352\270\260.kt" diff --git "a/src/main/kotlin/byeonghee/week47/\355\232\214\354\236\245\353\275\221\352\270\260.kt" "b/src/main/kotlin/byeonghee/week47/\355\232\214\354\236\245\353\275\221\352\270\260.kt" new file mode 100644 index 00000000..0e235150 --- /dev/null +++ "b/src/main/kotlin/byeonghee/week47/\355\232\214\354\236\245\353\275\221\352\270\260.kt" @@ -0,0 +1,61 @@ +package byeonghee.week47 + +class 소병희_회장뽑기 { + + companion object { + const val INF = 987_654_321 + + fun solve() = with(System.`in`.bufferedReader()) { + val n = readLine().toInt() + val adj = Array(n) { i -> IntArray(n) { j -> if (i == j) 0 else INF }} + + var a = 0 + var b = 0 + + readLine().split(" "). let { + a = it[0].toInt() + b = it[1].toInt() + } + + while(a != -1) { + adj[a-1][b-1] = 1 + adj[b-1][a-1] = 1 + + readLine().split(" "). let { + a = it[0].toInt() + b = it[1].toInt() + } + } + + for(k in 0 until n) { + for(i in 0 until n) for(j in 0 until n) { + val before = adj[i][j] + val detour = adj[i][k] + adj[k][j] + if (detour < before) adj[i][j] = detour + } + } + + var minScore = 987_654_321 + val candidates = ArrayDeque() + + for(i in 0 until n) { + val score = adj[i].maxOf{it} + if (score < minScore) { + minScore = score + candidates.clear() + candidates.add(i + 1) + } + else if (score == minScore) { + candidates.add(i + 1) + } + } + + println("$minScore ${candidates.size}") + println(candidates.joinToString(" ")) + } + } +} + +fun main() { + 소병희_회장뽑기.solve() +} \ No newline at end of file From 34d3e4e2ce0b72ca535ff74d27838e194edce040 Mon Sep 17 00:00:00 2001 From: bngsh Date: Sun, 8 Oct 2023 12:35:07 +0900 Subject: [PATCH 4/4] =?UTF-8?q?solve:=20=EC=9E=85=EA=B5=AD=EC=8B=AC?= =?UTF-8?q?=EC=82=AC?= 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" | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 "src/main/kotlin/byeonghee/week47/\354\236\205\352\265\255\354\213\254\354\202\254.kt" diff --git "a/src/main/kotlin/byeonghee/week47/\354\236\205\352\265\255\354\213\254\354\202\254.kt" "b/src/main/kotlin/byeonghee/week47/\354\236\205\352\265\255\354\213\254\354\202\254.kt" new file mode 100644 index 00000000..1919925f --- /dev/null +++ "b/src/main/kotlin/byeonghee/week47/\354\236\205\352\265\255\354\213\254\354\202\254.kt" @@ -0,0 +1,20 @@ +package byeonghee.week47 + +class 소병희_입국심사 { + fun solution(n: Int, times: IntArray): Long { + times.sort() + + var lb = 0L + var ub = times.last() * n.toLong() + var mid = 0L + + while(lb + 1 < ub) { + mid = lb + (ub - lb) / 2 + val cost = times.sumOf { mid / it } + if (cost < n) lb = mid + else ub = mid + } + + return ub + } +} \ No newline at end of file