From b06e7887414184cc5faef80c22762ae7a497c7fc Mon Sep 17 00:00:00 2001 From: bngsh Date: Thu, 14 Mar 2024 22:58:56 +0900 Subject: [PATCH 1/6] =?UTF-8?q?solve:=20=EC=8A=A4=ED=83=9D=20=EC=88=98?= =?UTF-8?q?=EC=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...4\355\203\235 \354\210\230\354\227\264.kt" | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 "src/main/kotlin/byeonghee/week54/\354\212\244\355\203\235 \354\210\230\354\227\264.kt" diff --git "a/src/main/kotlin/byeonghee/week54/\354\212\244\355\203\235 \354\210\230\354\227\264.kt" "b/src/main/kotlin/byeonghee/week54/\354\212\244\355\203\235 \354\210\230\354\227\264.kt" new file mode 100644 index 00000000..d27e9642 --- /dev/null +++ "b/src/main/kotlin/byeonghee/week54/\354\212\244\355\203\235 \354\210\230\354\227\264.kt" @@ -0,0 +1,36 @@ +package byeonghee.week54 + +class 소병희_스택수열 { + companion object { + fun solve() = with(System.`in`.bufferedReader()) { + val n = readLine().toInt() + val stack = ArrayDeque(n) + val sb = StringBuilder() + var numToPush = 1 + + repeat(n) { + val x = readLine().toInt() + + while (numToPush <= x) { + stack.addLast(numToPush++) + sb.appendLine("+") + } + if (stack.last() == x) { + stack.removeLast() + sb.appendLine("-") + } + + else { + println("NO") + return@with + } + } + + println(sb) + + } +} + +fun main() { + 소병희_스택수열.solve() +}} \ No newline at end of file From c203a29109b24def2087c105d4b85645ad28c401 Mon Sep 17 00:00:00 2001 From: bngsh Date: Sat, 16 Mar 2024 14:24:07 +0900 Subject: [PATCH 2/6] =?UTF-8?q?solve:=20=ED=95=AD=EC=B2=B4=20=EC=9D=B8?= =?UTF-8?q?=EC=8B=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...5\354\262\264 \354\235\270\354\213\235.kt" | 75 +++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 "src/main/kotlin/byeonghee/week54/\355\225\255\354\262\264 \354\235\270\354\213\235.kt" diff --git "a/src/main/kotlin/byeonghee/week54/\355\225\255\354\262\264 \354\235\270\354\213\235.kt" "b/src/main/kotlin/byeonghee/week54/\355\225\255\354\262\264 \354\235\270\354\213\235.kt" new file mode 100644 index 00000000..669d3d3b --- /dev/null +++ "b/src/main/kotlin/byeonghee/week54/\355\225\255\354\262\264 \354\235\270\354\213\235.kt" @@ -0,0 +1,75 @@ +package byeonghee.week54 + +class 소병희_항체인식 { + companion object { + val dr = intArrayOf(-1, 0, 1, 0) + val dc = intArrayOf(0, 1, 0, -1) + + fun solve() = with(System.`in`.bufferedReader()) { + val (n, m) = readLine().split(" ").map { it.toInt() } + val before = Array(n) { IntArray(m) } + val after = Array(n) { IntArray(m) } + val visited = Array(n) { BooleanArray(m) } + val q = ArrayDeque(n * m) + var shot = false + var answer = "YES" + var origin = 0 + var change = -1 + + repeat(n) { i -> + readLine().split(" ").forEachIndexed { j, v -> + before[i][j] = v.toInt() + } + } + + repeat(n) { i -> + readLine().split(" ").forEachIndexed { j, v -> + after[i][j] = v.toInt() + } + } + + outer@ for(i in 0 until n) inner@ for(j in 0 until m) { + if (visited[i][j]) continue@inner + if (shot && before[i][j] != after[i][j]) { + answer = "NO" + break@outer + } + + origin = before[i][j].also { visited[i][j] = true } + change = after[i][j].also { visited[i][j] = true } + q.add(intArrayOf(i, j)) + + while(q.isNotEmpty()) { + val (r, c) = q.removeFirst() + for(d in 0 until 4) { + val nr = r + dr[d] + val nc = c + dc[d] + if (nr !in 0 until n || nc !in 0 until m) continue + if (visited[nr][nc]) continue + if (before[nr][nc] == origin && after[nr][nc] == change) { + visited[nr][nc] = true + q.add(intArrayOf(nr, nc)) + } + else if (before[nr][nc] != origin) { + continue + } + else { + answer = "NO" + break@outer + } + } + } + + if (origin != change) { + shot = true + } + } + + println(answer) + } + } +} + +fun main() { + 소병희_항체인식.solve() +} \ No newline at end of file From add2b1221e1e48b7d75efa791d285a5ffebda476 Mon Sep 17 00:00:00 2001 From: bngsh Date: Sat, 16 Mar 2024 14:47:05 +0900 Subject: [PATCH 3/6] =?UTF-8?q?solve:=20=ED=86=A0=EB=A7=88=ED=86=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\355\206\240\353\247\210\355\206\240.kt" | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 "src/main/kotlin/byeonghee/week54/\355\206\240\353\247\210\355\206\240.kt" diff --git "a/src/main/kotlin/byeonghee/week54/\355\206\240\353\247\210\355\206\240.kt" "b/src/main/kotlin/byeonghee/week54/\355\206\240\353\247\210\355\206\240.kt" new file mode 100644 index 00000000..4fe4e70c --- /dev/null +++ "b/src/main/kotlin/byeonghee/week54/\355\206\240\353\247\210\355\206\240.kt" @@ -0,0 +1,53 @@ +package byeonghee.week54 + +class 소병희_토마토 { + companion object { + const val TOMATO = 1 + const val UNRIPE = 0 + const val EMPTY = -1 + + val dr = intArrayOf(1, 0, -1, 0) + val dc = intArrayOf(0, 1, 0, -1) + + fun solve() = with(System.`in`.bufferedReader()) { + val (m, n) = readLine().split(" ").map { it.toInt() } + val box = Array(n) { IntArray(m) } + val q = ArrayDeque(n * m) + var days = 0 + var unripe = 0 + + repeat(n) { i -> + readLine().split(" ").forEachIndexed { j, v -> + box[i][j] = v.toInt() + when (box[i][j]) { + TOMATO -> q.add(intArrayOf(i, j)) + UNRIPE -> unripe++ + } + } + } + + while(q.isNotEmpty()) { + val (r, c) = q.removeFirst() + for(d in 0 until 4) { + val nr = r + dr[d] + val nc = c + dc[d] + if (nr !in 0 until n || nc !in 0 until m) continue + if (box[nr][nc] != 0) continue + + box[nr][nc] = box[r][c] + 1 + q.add(intArrayOf(nr, nc)) + unripe-- + } + + days = box[r][c] + } + + if (unripe > 0) println(-1) + else println(days-1) + } + } +} + +fun main() { + 소병희_토마토.solve() +} \ No newline at end of file From b4693c8c2964158acac9cdf0e352a13d4f040db5 Mon Sep 17 00:00:00 2001 From: bngsh Date: Sat, 16 Mar 2024 16:32:42 +0900 Subject: [PATCH 4/6] =?UTF-8?q?solve:=20=EC=9A=B0=EC=B2=B4=EA=B5=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\354\232\260\354\262\264\352\265\255.kt" | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 "src/main/kotlin/byeonghee/week54/\354\232\260\354\262\264\352\265\255.kt" diff --git "a/src/main/kotlin/byeonghee/week54/\354\232\260\354\262\264\352\265\255.kt" "b/src/main/kotlin/byeonghee/week54/\354\232\260\354\262\264\352\265\255.kt" new file mode 100644 index 00000000..7faeb492 --- /dev/null +++ "b/src/main/kotlin/byeonghee/week54/\354\232\260\354\262\264\352\265\255.kt" @@ -0,0 +1,41 @@ +package byeonghee.week54 + +import java.util.PriorityQueue +import kotlin.math.abs + +class 소병희_우체국 { + companion object { + fun solve() = with(System.`in`.bufferedReader()) { + val n = readLine().toInt() + var total = 0L + val pq = PriorityQueue { a, b -> (a[0] - b[0]).toInt() } + + repeat(n) { i -> + val (x, a) = readLine().split(" ").map { it.toLong() } + pq.add(longArrayOf(x, a)) + total += a + } + + var people = 0L + var diff = total + var answer = 0L + + while(pq.isNotEmpty()) { + val (x, a) = pq.poll() + + if (abs(total - a - people * 2) < diff) { + diff = abs(total - a - people * 2) + answer = x + people += a + } + else break + } + + println(answer) + } + } +} + +fun main() { + 소병희_우체국.solve() +} \ No newline at end of file From 35c01363d7d2bbd446677a8d716641fc5eaf31dc Mon Sep 17 00:00:00 2001 From: bngsh Date: Sat, 16 Mar 2024 16:51:10 +0900 Subject: [PATCH 5/6] =?UTF-8?q?solve:=20=EB=AC=B8=EC=9E=90=EC=97=B4=20?= =?UTF-8?q?=EA=B2=8C=EC=9E=84=202?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...354\227\264 \352\262\214\354\236\204 2.kt" | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 "src/main/kotlin/byeonghee/week54/\353\254\270\354\236\220\354\227\264 \352\262\214\354\236\204 2.kt" diff --git "a/src/main/kotlin/byeonghee/week54/\353\254\270\354\236\220\354\227\264 \352\262\214\354\236\204 2.kt" "b/src/main/kotlin/byeonghee/week54/\353\254\270\354\236\220\354\227\264 \352\262\214\354\236\204 2.kt" new file mode 100644 index 00000000..c533cc2c --- /dev/null +++ "b/src/main/kotlin/byeonghee/week54/\353\254\270\354\236\220\354\227\264 \352\262\214\354\236\204 2.kt" @@ -0,0 +1,39 @@ +package byeonghee.week54 + +class 소병희_문자열게임2 { + companion object { + fun solve() = with(System.`in`.bufferedReader()) { + val tc = readLine().toInt() + val sb = StringBuilder() + + for(t in 0 until tc) { + val letter = Array(26) { ArrayDeque(10_000)} + + readLine().forEachIndexed { i, c -> + letter[c - 'a'].add(i) + } + + val k = readLine().toInt() + var minDist = 20_000 + var maxDist = 0 + for(list in letter) { + if (list.size < k) continue + for(i in k-1 until list.size) { + val dist = list[i] - list[i-k+1] + 1 + if (dist < minDist) minDist = dist + if (dist > maxDist) maxDist = dist + } + } + + if (maxDist == 0) sb.appendLine(-1) + else sb.appendLine("$minDist $maxDist") + } + + println(sb) + } + } +} + +fun main() { + 소병희_문자열게임2.solve() +} \ No newline at end of file From fb69c2cb8280a099165f49a0b4818d5cc074a03b Mon Sep 17 00:00:00 2001 From: bngsh Date: Sat, 16 Mar 2024 17:08:03 +0900 Subject: [PATCH 6/6] =?UTF-8?q?solve:=20DFS=EC=99=80=20BFS?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../byeonghee/week54/DFS\354\231\200 BFS.kt" | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 "src/main/kotlin/byeonghee/week54/DFS\354\231\200 BFS.kt" diff --git "a/src/main/kotlin/byeonghee/week54/DFS\354\231\200 BFS.kt" "b/src/main/kotlin/byeonghee/week54/DFS\354\231\200 BFS.kt" new file mode 100644 index 00000000..3bcc6c28 --- /dev/null +++ "b/src/main/kotlin/byeonghee/week54/DFS\354\231\200 BFS.kt" @@ -0,0 +1,56 @@ +package byeonghee.week54 + +class 소병희_DFS와BFS { + companion object { + fun solve() = with(System.`in`.bufferedReader()) { + val (n, m, v) = readLine().split(" ").map { it.toInt() } + val adj = Array(n+1) { IntArray(n+1) } + val sb = StringBuilder() + + repeat(m) { + val (a, b) = readLine().split(" ").map { it.toInt() } + adj[a][b] = 1 + adj[b][a] = 1 + } + + fun dfs(p: Int, visited: BooleanArray) { + sb.append(p) + sb.append(" ") + + for(i in 1 .. n) { + if (adj[p][i] == 1 && visited[i].not()) { + visited[i] = true + dfs(i, visited) + } + } + } + + fun bfs(_p: Int, visited: BooleanArray) { + val q = ArrayDeque() + q.add(_p) + + while(q.isNotEmpty()) { + val p = q.removeFirst() + sb.append(p) + sb.append(" ") + for(i in 1 .. n) { + if (adj[p][i] == 1 && visited[i].not()) { + visited[i] = true + q.add(i) + } + } + } + } + + dfs(v, BooleanArray(n+1).apply { this[v] = true }) + sb.appendLine() + bfs(v, BooleanArray(n+1).apply { this[v] = true }) + + println(sb) + } + } +} + +fun main() { + 소병희_DFS와BFS.solve() +} \ No newline at end of file