From 82ac0c46f545e4567e23352f8571cf109be00472 Mon Sep 17 00:00:00 2001 From: jhg3410 <80373033+jhg3410@users.noreply.github.com> Date: Sun, 8 Oct 2023 11:50:33 +0900 Subject: [PATCH 1/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 --- .../heejik/47week/A\354\231\200 B 2.kt" | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 "src/main/kotlin/heejik/47week/A\354\231\200 B 2.kt" diff --git "a/src/main/kotlin/heejik/47week/A\354\231\200 B 2.kt" "b/src/main/kotlin/heejik/47week/A\354\231\200 B 2.kt" new file mode 100644 index 00000000..6c117b7a --- /dev/null +++ "b/src/main/kotlin/heejik/47week/A\354\231\200 B 2.kt" @@ -0,0 +1,37 @@ +package heejik.`47week` + +class `A와 B 2` { + + fun solve() { + val s = readln() + val t = readln() + val queue = ArrayDeque() + queue.add(t) + + while (queue.isNotEmpty()) { + val nowString = queue.removeFirst() + if (nowString.length == s.length) { + if (nowString == s) { + println(1) + return + } + continue + } + + if (nowString.last() == 'A') { + queue.add(nowString.dropLast(1)) + } + + if (nowString.first() == 'B') { + queue.add(nowString.reversed().dropLast(1)) + } + } + + + println(0) + } +} + +fun main() { + `A와 B 2`().solve() +} \ No newline at end of file From 5a7436bca5894e4ed6f68a1e6664b6e5859bb546 Mon Sep 17 00:00:00 2001 From: jhg3410 <80373033+jhg3410@users.noreply.github.com> Date: Sun, 8 Oct 2023 11:50:54 +0900 Subject: [PATCH 2/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" | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 "src/main/kotlin/heejik/47week/\354\225\214\352\263\240\354\212\244\355\214\237.kt" diff --git "a/src/main/kotlin/heejik/47week/\354\225\214\352\263\240\354\212\244\355\214\237.kt" "b/src/main/kotlin/heejik/47week/\354\225\214\352\263\240\354\212\244\355\214\237.kt" new file mode 100644 index 00000000..b9e40340 --- /dev/null +++ "b/src/main/kotlin/heejik/47week/\354\225\214\352\263\240\354\212\244\355\214\237.kt" @@ -0,0 +1,64 @@ +package heejik.`47week` + +import kotlin.properties.Delegates + +class 알고스팟 { + + data class Pos( + val x: Int, + val y: Int + ) + + val dx = listOf(1, -1, 0, 0) + val dy = listOf(0, 0, 1, -1) + + var m by Delegates.notNull() + var n by Delegates.notNull() + private val maze = mutableListOf>() + lateinit var visited: List> + + fun solve() { + readln().split(' ').map { it.toInt() }.run { + n = this[0] + m = this[1] + } + visited = MutableList(m) { MutableList(n) { false } } + + repeat(m) { + maze.add(readln().toList().map { it.digitToInt() }) + } + + findAnswer().run { println(this) } + } + + private fun findAnswer(): Int { + val dequeue = ArrayDeque>() + dequeue.add(Pos(0, 0) to 0) + + while (dequeue.isNotEmpty()) { + val (pos, count) = dequeue.removeFirst() + + if (pos.x == m - 1 && pos.y == n - 1) { + return count + } + + for (i in 0 until 4) { + val nx = pos.x + dx[i] + val ny = pos.y + dy[i] + if (nx in 0 until m && ny in 0 until n) { + if (visited[nx][ny].not()) { + if (maze[nx][ny] == 0) dequeue.addFirst(Pos(nx, ny) to count) + if (maze[nx][ny] == 1) dequeue.addLast(Pos(nx, ny) to count + 1) + visited[nx][ny] = true + } + } + } + } + + return Int.MAX_VALUE + } +} + +fun main() { + 알고스팟().solve() +} \ No newline at end of file From 214f78f6c1967239484b7d313d5637f84fc00710 Mon Sep 17 00:00:00 2001 From: jhg3410 <80373033+jhg3410@users.noreply.github.com> Date: Sun, 8 Oct 2023 11:51:17 +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" | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 "src/main/kotlin/heejik/47week/\355\232\214\354\236\245\353\275\221\352\270\260.kt" diff --git "a/src/main/kotlin/heejik/47week/\355\232\214\354\236\245\353\275\221\352\270\260.kt" "b/src/main/kotlin/heejik/47week/\355\232\214\354\236\245\353\275\221\352\270\260.kt" new file mode 100644 index 00000000..93e07681 --- /dev/null +++ "b/src/main/kotlin/heejik/47week/\355\232\214\354\236\245\353\275\221\352\270\260.kt" @@ -0,0 +1,46 @@ +package heejik.`47week` + +import kotlin.math.min + +class 회장뽑기 { + + fun solve() { + val n = readln().toInt() + val board = MutableList(n + 1) { MutableList(n + 1) { Int.MAX_VALUE } } + repeat(n + 1) { + board[it][it] = 0 + } + + while (true) { + val (a, b) = readln().split(' ').map { it.toInt() } + if (a == -1) break + board[a][b] = 1 + board[b][a] = 1 + } + + + for (k in 1..n) { + for (i in 1..n) { + for (j in 1..n) { + if (board[i][k] == Int.MAX_VALUE || board[k][j] == Int.MAX_VALUE) continue + board[i][j] = min(board[i][j], board[i][k] + board[k][j]) + } + } + } + + val minScore = board.drop(1).minOf { it.filter { it != Int.MAX_VALUE }.max() } + val candidates = mutableListOf() + + board.forEachIndexed { index, ints -> + if (ints.filter { it != Int.MAX_VALUE }.max() == minScore) + candidates.add(index) + } + println("$minScore ${candidates.count()}") + println(candidates.joinToString(" ")) + } +} + + +fun main() { + 회장뽑기().solve() +} \ No newline at end of file From 66c365453be7f6f76178a9e32fccd21eaf27a435 Mon Sep 17 00:00:00 2001 From: jhg3410 <80373033+jhg3410@users.noreply.github.com> Date: Sun, 8 Oct 2023 11:51:25 +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" | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 "src/main/kotlin/heejik/47week/\354\236\205\352\265\255\354\213\254\354\202\254.kt" diff --git "a/src/main/kotlin/heejik/47week/\354\236\205\352\265\255\354\213\254\354\202\254.kt" "b/src/main/kotlin/heejik/47week/\354\236\205\352\265\255\354\213\254\354\202\254.kt" new file mode 100644 index 00000000..2b518235 --- /dev/null +++ "b/src/main/kotlin/heejik/47week/\354\236\205\352\265\255\354\213\254\354\202\254.kt" @@ -0,0 +1,22 @@ +package heejik.`47week` + +class 입국심사 { + fun solution(n: Int, times: IntArray): Long { + var minTime : Long = 1L + var maxTime : Long = times.maxOrNull()!!.toLong() * n + + while (minTime <= maxTime) { + val midTime = (minTime + maxTime) / 2 + + var count = 0L + times.forEach { time -> count += midTime / time } + + if (count >= n) { + maxTime = midTime - 1 + } else { + minTime = midTime + 1 + } + } + return minTime + } +} \ No newline at end of file