From 7433cc69fbc27f5f983f2da85951f3d752ac3a24 Mon Sep 17 00:00:00 2001 From: bngsh Date: Fri, 21 Oct 2022 23:19:07 +0900 Subject: [PATCH 1/6] =?UTF-8?q?solve:=20=EA=B7=BC=EC=86=90=EC=8B=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\352\267\274\354\206\220\354\213\244.kt" | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 "src/main/kotlin/byeonghee/6week/\352\267\274\354\206\220\354\213\244.kt" diff --git "a/src/main/kotlin/byeonghee/6week/\352\267\274\354\206\220\354\213\244.kt" "b/src/main/kotlin/byeonghee/6week/\352\267\274\354\206\220\354\213\244.kt" new file mode 100644 index 00000000..bd45118e --- /dev/null +++ "b/src/main/kotlin/byeonghee/6week/\352\267\274\354\206\220\354\213\244.kt" @@ -0,0 +1,56 @@ +package byeonghee.`6week` + +import java.io.* + +class `소병희_근손실` { + companion object { + fun getSolution(): Solution { + return Solution() + } + } + + class Solution { + val br = BufferedReader(InputStreamReader(System.`in`)) + + var n = 0 + var k = 0 + var workouts = IntArray(0) + + val visited = BooleanArray(8) { false } + var curPerm = 0 + var answer = 0 + + fun solution() { + br.readLine().split(" ").map { it.toInt() }.run { + n = first() + k = last() + } + workouts = br.readLine().split(" ").map { it.toInt() - k }.toIntArray() + + makePerm(0) + println(answer) + } + + fun makePerm(len: Int) { + if (len == n) { + answer++ + return + } + + for(i in 0 until n) { + if (visited[i]) continue + if (curPerm + workouts[i] < 0) continue + + visited[i] = true + curPerm += workouts[i] + makePerm(len + 1) + curPerm -= workouts[i] + visited[i] = false + } + } + } +} + +fun main() { + `소병희_근손실`.getSolution().solution() +} \ No newline at end of file From 3f28fbba6b866cd67fd55fd1e16020c1e8a941fc Mon Sep 17 00:00:00 2001 From: bngsh Date: Sat, 22 Oct 2022 13:26:10 +0900 Subject: [PATCH 2/6] =?UTF-8?q?solve:=20=EB=B9=84=EC=8A=B7=ED=95=9C=20?= =?UTF-8?q?=EB=8B=A8=EC=96=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...7\355\225\234 \353\213\250\354\226\264.kt" | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 "src/main/kotlin/byeonghee/6week/\353\271\204\354\212\267\355\225\234 \353\213\250\354\226\264.kt" diff --git "a/src/main/kotlin/byeonghee/6week/\353\271\204\354\212\267\355\225\234 \353\213\250\354\226\264.kt" "b/src/main/kotlin/byeonghee/6week/\353\271\204\354\212\267\355\225\234 \353\213\250\354\226\264.kt" new file mode 100644 index 00000000..0aea0c77 --- /dev/null +++ "b/src/main/kotlin/byeonghee/6week/\353\271\204\354\212\267\355\225\234 \353\213\250\354\226\264.kt" @@ -0,0 +1,64 @@ +package byeonghee.`6week` + +import java.io.* + +class `소병희_비슷한 단어` { + companion object { + fun getSolution(): Solution { + return Solution() + } + } + + class Solution { + val br = BufferedReader(InputStreamReader(System.`in`)) + var answer = 0 + + fun solution() { + val n = br.readLine().toInt() + val first = br.readLine().toList().sorted().joinToString("") + val words = Array(n-1) { br.readLine().toList().sorted().joinToString("") } + + words.forEach { + if (first.length > it.length) compare(it, first) else compare(first, it) + } + + println(answer) + } + + fun compare(short: String, long: String) { + if ((long.length - short.length) > 1) return + + if (long.length > short.length) { + for(i in long.indices) { + if (long.removeRange(i, i + 1) == short) { + answer ++ + return + } + } + return + } + + if (short == long) { + answer ++ + return + } + + for(i in long.indices) { + if (long[i] == short[i]) continue + + for(j in i until short.length) { + if ((long.drop(i + 1) == short.substring(i, j).plus(short.drop(j+1))) + || (short.drop(i + 1) == long.substring(i, j).plus(long.drop(j+1)))) { + answer ++ + return + } + } + return + } + } + } +} + +fun main() { + `소병희_비슷한 단어`.getSolution().solution() +} \ No newline at end of file From 7b7a04cec6d07e7e8a8b6179338f3aa16885e2de Mon Sep 17 00:00:00 2001 From: bngsh Date: Sat, 22 Oct 2022 14:13:01 +0900 Subject: [PATCH 3/6] =?UTF-8?q?solve:=20=EC=95=84=EA=B8=B0=20=EC=83=81?= =?UTF-8?q?=EC=96=B4=202?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...352\270\260 \354\203\201\354\226\264 2.kt" | 84 +++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 "src/main/kotlin/byeonghee/6week/\354\225\204\352\270\260 \354\203\201\354\226\264 2.kt" diff --git "a/src/main/kotlin/byeonghee/6week/\354\225\204\352\270\260 \354\203\201\354\226\264 2.kt" "b/src/main/kotlin/byeonghee/6week/\354\225\204\352\270\260 \354\203\201\354\226\264 2.kt" new file mode 100644 index 00000000..d478618f --- /dev/null +++ "b/src/main/kotlin/byeonghee/6week/\354\225\204\352\270\260 \354\203\201\354\226\264 2.kt" @@ -0,0 +1,84 @@ +package byeonghee.`6week` + +import java.io.* + +class `소병희_아기 상어 2` { + companion object { + fun getSolution(): Solution { + return Solution() + } + } + + class Solution { + val br = BufferedReader(InputStreamReader(System.`in`)) + + data class Pos(val r : Int, val c : Int) { + operator fun plus(p : Pos) : Pos { + return Pos(r + p.r, c + p.c) + } + + fun isInBound(h: Int, w: Int) : Boolean { + return r in 0 until h && c in 0 until w + } + } + + val mvs = listOf( + Pos(-1, 0), + Pos(-1, 1), + Pos(0, 1), + Pos(1, 1), + Pos(1, 0), + Pos(1, -1), + Pos(0, -1), + Pos(-1, -1) + ) + + data class Safe(val p: Pos, val d: Int) + + var n = 0 + var m = 0 + var sea = Array(0) { IntArray(0) } + + var sharks = ArrayDeque() + var cur = Safe(Pos(0, 0), 0) + var nxt = Pos(0, 0) + + + fun solution() { + br.readLine().split(" ").map{ it.toInt() }.run { + n = first() + m = last() + } + sea = Array(n) { IntArray(m){ Int.MAX_VALUE } } + + repeat(n) { r -> + br.readLine().split(" ").let { + for(c in it.indices) { + if (it[c] == "1") sharks.add(Safe(Pos(r, c), 0)) + } + } + } + + while(sharks.isNotEmpty()) { + cur = sharks.removeFirst() + if (sea[cur.p.r][cur.p.c] <= cur.d) continue + + with(cur) { + sea[p.r][p.c] = d + for (mv in mvs) { + nxt = p + mv + if (nxt.isInBound(n, m).not()) continue + if (sea[nxt.r][nxt.c] <= d + 1) continue + sharks.add(Safe(nxt, d + 1)) + } + } + } + + println(sea.maxOf { it.maxOf{ it } }) + } + } +} + +fun main() { + `소병희_아기 상어 2`.getSolution().solution() +} \ No newline at end of file From 90c6e04ce90b7703bebf6527a17f9e634fadded8 Mon Sep 17 00:00:00 2001 From: bngsh Date: Sat, 22 Oct 2022 16:58:19 +0900 Subject: [PATCH 4/6] =?UTF-8?q?solve:=20=ED=8A=B8=EB=A6=AC=EC=9D=98=20?= =?UTF-8?q?=EB=B6=80=EB=AA=A8=20=EC=B0=BE=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...0\353\252\250 \354\260\276\352\270\260.kt" | 92 +++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 "src/main/kotlin/byeonghee/6week/\355\212\270\353\246\254\354\235\230 \353\266\200\353\252\250 \354\260\276\352\270\260.kt" diff --git "a/src/main/kotlin/byeonghee/6week/\355\212\270\353\246\254\354\235\230 \353\266\200\353\252\250 \354\260\276\352\270\260.kt" "b/src/main/kotlin/byeonghee/6week/\355\212\270\353\246\254\354\235\230 \353\266\200\353\252\250 \354\260\276\352\270\260.kt" new file mode 100644 index 00000000..73f7cd13 --- /dev/null +++ "b/src/main/kotlin/byeonghee/6week/\355\212\270\353\246\254\354\235\230 \353\266\200\353\252\250 \354\260\276\352\270\260.kt" @@ -0,0 +1,92 @@ +package byeonghee.`6week` + +import java.io.* + +class `소병희_트리의 부모 찾기` { + companion object { + fun getSolution(): Solution { + return Solution() + } + } + + class Solution { + val br = BufferedReader(InputStreamReader(System.`in`)) + + var n = 0 + var parents = IntArray(0) + var edges = mutableMapOf>() + var q = ArrayDeque>() + lateinit var cur: Pair + + fun solution() { + n = br.readLine().toInt() + parents = IntArray(n + 1) + + repeat(n-1) { i -> + br.readLine().split(" ").map{ it.toInt() }.run { + edges.getOrPut(first()) { mutableListOf() } + edges[first()]!!.add(last()) + edges.getOrPut(last()) { mutableListOf() } + edges[last()]!!.add(first()) + if (first() == 1) q.add(Pair(first(), last())) + else if (last() == 1) q.add(Pair(last(), first())) + } + } + + while(q.isNotEmpty()) { + cur = q.removeFirst() + parents[cur.second] = cur.first + for(i in edges[cur.second]!!) { + if (parents[i] == 0) q.add(Pair(cur.second, i)) + } + } + + for(r in 2..n) { + println(parents[r]) + } + } + } +} + +fun main() { + `소병희_트리의 부모 찾기`.getSolution().solution() +} + +/*var n = 0 +var parents = IntArray(0) +var depths = IntArray(0) +var child = 0 +var parent = 0 + +fun main() { + n = br.readLine().toInt() + parents = IntArray(n + 1) { -1 } + parents[1] = 0 + depths = IntArray(n + 1) { 100001 } + depths[0] = -1 + depths[1] = 0 + + repeat(n-1) { + br.readLine().trim().split(" ").map{ it.toInt() }.run { + if (depths[first()] > depths[last()]) { + updateParents(first(), last()) + } + else { + updateParents(last(), first()) + } + } + } + + for(r in 2..n) { + println(parents[r]) + } +} + +fun updateParents(child: Int, parent: Int) { + var tmp = parents[child] + parents[child] = parent + depths[child] = depths[parent] + 1 + + if (tmp == -1) return + updateParents(tmp, child) +}*/ \ No newline at end of file From a2c1495a7413b100351427617d1e2b5906c9c66a Mon Sep 17 00:00:00 2001 From: bngsh Date: Sat, 22 Oct 2022 19:19:42 +0900 Subject: [PATCH 5/6] =?UTF-8?q?solve:=20=ED=9A=8C=EC=9D=98=EC=8B=A4=20?= =?UTF-8?q?=EB=B0=B0=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...0\354\213\244 \353\260\260\354\240\225.kt" | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 "src/main/kotlin/byeonghee/6week/\355\232\214\354\235\230\354\213\244 \353\260\260\354\240\225.kt" diff --git "a/src/main/kotlin/byeonghee/6week/\355\232\214\354\235\230\354\213\244 \353\260\260\354\240\225.kt" "b/src/main/kotlin/byeonghee/6week/\355\232\214\354\235\230\354\213\244 \353\260\260\354\240\225.kt" new file mode 100644 index 00000000..3fbd0a30 --- /dev/null +++ "b/src/main/kotlin/byeonghee/6week/\355\232\214\354\235\230\354\213\244 \353\260\260\354\240\225.kt" @@ -0,0 +1,33 @@ +package byeonghee.`6week` + +import java.io.* +import java.util.PriorityQueue + +val br = BufferedReader(InputStreamReader(System.`in`)) + +data class Meeting(val s: Int, val e: Int) + +var n = 0 +val meetings = PriorityQueue(Comparator { a, b -> if (a.e == b.e) a.s - b.s else a.e - b.e }) +var answer = 0 +var curLastT = 0 +lateinit var nxt : Meeting + +fun main() { + n = br.readLine().toInt() + repeat(n) { + br.readLine().split(" ").map{ it.toInt() }.run{ + meetings.add(Meeting(first(), last())) + } + } + + while(meetings.isNotEmpty()) { + nxt = meetings.poll() + if (curLastT <= nxt.s) { + curLastT = nxt.e + answer++ + } + } + + println(answer) +} \ No newline at end of file From 376afb4a0921695f2a355373db74d12af7e805a4 Mon Sep 17 00:00:00 2001 From: bngsh Date: Sat, 22 Oct 2022 19:25:10 +0900 Subject: [PATCH 6/6] =?UTF-8?q?chore:=20=EC=A0=84=EC=97=AD=EB=B3=80?= =?UTF-8?q?=EC=88=98=20=EC=88=A8=EA=B9=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...0\354\213\244 \353\260\260\354\240\225.kt" | 54 ++++++++++++------- 1 file changed, 34 insertions(+), 20 deletions(-) diff --git "a/src/main/kotlin/byeonghee/6week/\355\232\214\354\235\230\354\213\244 \353\260\260\354\240\225.kt" "b/src/main/kotlin/byeonghee/6week/\355\232\214\354\235\230\354\213\244 \353\260\260\354\240\225.kt" index 3fbd0a30..b5448d92 100644 --- "a/src/main/kotlin/byeonghee/6week/\355\232\214\354\235\230\354\213\244 \353\260\260\354\240\225.kt" +++ "b/src/main/kotlin/byeonghee/6week/\355\232\214\354\235\230\354\213\244 \353\260\260\354\240\225.kt" @@ -3,31 +3,45 @@ package byeonghee.`6week` import java.io.* import java.util.PriorityQueue -val br = BufferedReader(InputStreamReader(System.`in`)) +class `소병희_회의실 배정` { + companion object { + fun getSolution(): Solution { + return Solution() + } + } -data class Meeting(val s: Int, val e: Int) + class Solution { + val br = BufferedReader(InputStreamReader(System.`in`)) -var n = 0 -val meetings = PriorityQueue(Comparator { a, b -> if (a.e == b.e) a.s - b.s else a.e - b.e }) -var answer = 0 -var curLastT = 0 -lateinit var nxt : Meeting + data class Meeting(val s: Int, val e: Int) -fun main() { - n = br.readLine().toInt() - repeat(n) { - br.readLine().split(" ").map{ it.toInt() }.run{ - meetings.add(Meeting(first(), last())) - } - } + var n = 0 + val meetings = PriorityQueue(Comparator { a, b -> if (a.e == b.e) a.s - b.s else a.e - b.e }) + var answer = 0 + var curLastT = 0 + lateinit var nxt : Meeting + + fun solution() { + n = br.readLine().toInt() + repeat(n) { + br.readLine().split(" ").map{ it.toInt() }.run{ + meetings.add(Meeting(first(), last())) + } + } - while(meetings.isNotEmpty()) { - nxt = meetings.poll() - if (curLastT <= nxt.s) { - curLastT = nxt.e - answer++ + while(meetings.isNotEmpty()) { + nxt = meetings.poll() + if (curLastT <= nxt.s) { + curLastT = nxt.e + answer++ + } + } + + println(answer) } } +} - println(answer) +fun main() { + `소병희_회의실 배정`.getSolution() } \ No newline at end of file