diff --git "a/src/main/kotlin/byeonghee/23week/\353\241\234\353\264\207 \354\262\255\354\206\214\352\270\260.kt" "b/src/main/kotlin/byeonghee/23week/\353\241\234\353\264\207 \354\262\255\354\206\214\352\270\260.kt" new file mode 100644 index 00000000..a0917ede --- /dev/null +++ "b/src/main/kotlin/byeonghee/23week/\353\241\234\353\264\207 \354\262\255\354\206\214\352\270\260.kt" @@ -0,0 +1,63 @@ +package byeonghee.`23week` + +import java.io.* + +class 소병희_로봇청소기 { + + companion object { + const val DIRTY = 0 + const val WALL = 1 + const val CLEAR = 2 + + val dr = arrayOf(-1, 0, 1, 0) + val dc = arrayOf(0, 1, 0, -1) + + fun solve() : Unit = with(BufferedReader(InputStreamReader(System.`in`))) { + val (n, m) = readLine().split(" ").map { it.toInt() } + var (r, c, d) = readLine().split(" ").map { it.toInt() } + val room = Array(n) { IntArray(m) } + + for(r in 0 until n) { + readLine().split(" ").forEachIndexed { c, v -> + room[r][c] = v.toInt() + } + } + + var stop = false + var back = false + var cleaned = 0 + while(stop.not()) { + if (room[r][c] == DIRTY) { + cleaned++ + room[r][c] = CLEAR + } + + back = true + for (i in 0 until 4) { + d = (d + 3) % 4 + if (room[r + dr[d]][c + dc[d]] == DIRTY) { + r += dr[d] + c += dc[d] + back = false + break + } + } + if (back.not()) continue + + if (room[r - dr[d]][c - dc[d]] == WALL) { + stop = true + } + else { + r -= dr[d] + c -= dc[d] + } + } + + println(cleaned) + } + } +} + +fun main() { + 소병희_로봇청소기.solve() +} \ No newline at end of file diff --git "a/src/main/kotlin/byeonghee/23week/\353\263\264\353\254\274\354\204\254.kt" "b/src/main/kotlin/byeonghee/23week/\353\263\264\353\254\274\354\204\254.kt" new file mode 100644 index 00000000..a90e57b7 --- /dev/null +++ "b/src/main/kotlin/byeonghee/23week/\353\263\264\353\254\274\354\204\254.kt" @@ -0,0 +1,57 @@ +package byeonghee.`23week` + +import java.io.* + +class 소병희_보물섬 { + + companion object { + data class Trip(val r: Int, val c: Int, val dist: Int) + + val dr = arrayOf(-1, 0, 1, 0) + val dc = arrayOf(0, 1, 0, -1) + + fun solve(): Unit = with(BufferedReader(InputStreamReader(System.`in`))) { + val (h, w) = readLine().split(" ").map { it.toInt() } + val treasureMap = Array(h + 2) { CharArray(w + 2) { 'W' } } + val queue = ArrayDeque() + var answer = 0 + var trip: Trip + var nxtR = 0 + var nxtC = 0 + + for(r in 1 until h + 1) { + readLine().forEachIndexed { c, v -> + treasureMap[r][c + 1] = v + } + } + + for(r in 1 until h + 2) for(c in 1 until w + 2) { + if (treasureMap[r][c] == 'W') continue + val visited = Array(h + 2) { BooleanArray(w + 2) } + queue.add(Trip(r, c, 0)) + + while(queue.isNotEmpty()) { + trip = queue.removeFirst() + if (visited[trip.r][trip.c]) continue + + answer = maxOf(answer, trip.dist) + visited[trip.r][trip.c] = true + + for(d in 0 until 4) { + nxtR = trip.r + dr[d] + nxtC = trip.c + dc[d] + if (treasureMap[nxtR][nxtC] == 'W') continue + + queue.add(Trip(nxtR, nxtC, trip.dist + 1)) + } + } + } + + println(answer) + } + } +} + +fun main() { + 소병희_보물섬.solve() +} \ No newline at end of file diff --git "a/src/main/kotlin/byeonghee/23week/\354\204\274\354\204\234.kt" "b/src/main/kotlin/byeonghee/23week/\354\204\274\354\204\234.kt" new file mode 100644 index 00000000..a3e7d1a1 --- /dev/null +++ "b/src/main/kotlin/byeonghee/23week/\354\204\274\354\204\234.kt" @@ -0,0 +1,38 @@ +package byeonghee.`23week` + +import java.io.* +import java.util.* + +class 소병희_센서 { + + companion object { + fun solve(): Unit = with(BufferedReader(InputStreamReader(System.`in`))) { + val n = readLine().toInt() + val k = readLine().toInt() + val sensors = readLine().split(" ").map { it.toInt() }.sorted() + var answer = sensors.last() - sensors.first() + + if (n == 1) { + println(0) + return + } + + val pq = PriorityQueue(n - 1, Collections.reverseOrder()) + + for(i in 1 until n) { + pq.add(sensors[i] - sensors[i - 1]) + } + + for(i in 0 until k - 1) { + if (pq.isEmpty()) break + answer -= pq.poll() + } + + println(answer) + } + } +} + +fun main() { + 소병희_센서.solve() +} \ No newline at end of file diff --git "a/src/main/kotlin/byeonghee/23week/\355\225\251\353\266\204\355\225\264.kt" "b/src/main/kotlin/byeonghee/23week/\355\225\251\353\266\204\355\225\264.kt" new file mode 100644 index 00000000..bcc9f047 --- /dev/null +++ "b/src/main/kotlin/byeonghee/23week/\355\225\251\353\266\204\355\225\264.kt" @@ -0,0 +1,25 @@ +package byeonghee.`23week` + +import java.io.* + +class 소병희_합분해 { + + companion object { + const val MOD = 1_000_000_000 + + fun solve(): Unit = with(BufferedReader(InputStreamReader(System.`in`))) { + val (n, k) = readLine().split(" ").map { it.toInt() } + val dp = Array(n + 1) { IntArray(k) { 1 } } + + for(r in 1 .. n) for(c in 1 until k) { + dp[r][c] = (dp[r - 1][c] + dp[r][c - 1]) % MOD + } + + println(dp[n][k - 1]) + } + } +} + +fun main() { + 소병희_합분해.solve() +} \ No newline at end of file