From eb575182b6aa16fa2aa92aa075bfc1b7b9d7acbf Mon Sep 17 00:00:00 2001 From: bngsh Date: Mon, 10 Oct 2022 19:39:25 +0900 Subject: [PATCH 01/14] =?UTF-8?q?solve:=20=EA=B8=B0=EC=B0=A8=EA=B0=80=20?= =?UTF-8?q?=EC=96=B4=EB=91=A0=EC=9D=84=20=ED=97=A4=EC=B9=98=EA=B3=A0=20?= =?UTF-8?q?=EC=9D=80=ED=95=98=EC=88=98=EB=A5=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...00\355\225\230\354\210\230\353\245\274.kt" | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 "src/2week/byeonghee/\352\270\260\354\260\250\352\260\200 \354\226\264\353\221\240\354\235\204 \355\227\244\354\271\230\352\263\240 \354\235\200\355\225\230\354\210\230\353\245\274.kt" diff --git "a/src/2week/byeonghee/\352\270\260\354\260\250\352\260\200 \354\226\264\353\221\240\354\235\204 \355\227\244\354\271\230\352\263\240 \354\235\200\355\225\230\354\210\230\353\245\274.kt" "b/src/2week/byeonghee/\352\270\260\354\260\250\352\260\200 \354\226\264\353\221\240\354\235\204 \355\227\244\354\271\230\352\263\240 \354\235\200\355\225\230\354\210\230\353\245\274.kt" new file mode 100644 index 0000000..41f8ebf --- /dev/null +++ "b/src/2week/byeonghee/\352\270\260\354\260\250\352\260\200 \354\226\264\353\221\240\354\235\204 \355\227\244\354\271\230\352\263\240 \354\235\200\355\225\230\354\210\230\353\245\274.kt" @@ -0,0 +1,63 @@ +package `2week`.byeonghee + +/** + * 접근방식: 비트마스킹, distinct() + * 각 열차를 20개의 비트를 사용하는 정수로 표현하고 + * 모든 명령이 끝난 후 열차를 모아놓은 IntArray에 distinct().size로 은하수를 건너는 개수를 구한다. + */ + +import java.io.* + +class `소병희_기차가 어둠을 헤치고 은하수를` { + companion object { + fun getSolution() : Solution { + return Solution() + } + } + + class Solution { + companion object { + const val GET_ON = 1 + const val GET_OFF = 2 + const val MV_BACK = 3 + const val MV_FORE = 4 + + const val masking = (1 shl 20) - 1 + } + + val br = BufferedReader(InputStreamReader(System.`in`)) + + var comm = 0 + var tr = 0 + var ps = 0 + + fun solution() { + val (N, M) = br.readLine().split(" ").map{ it.toInt() } + val trains = IntArray(N) + + repeat(M) { + br.readLine().split(" ").map{ it.toInt() }.run { + comm = component1() + tr = component2() + if (size > 2) ps = component3() + } + + trains[tr - 1] = trains[tr - 1].let { + when(comm) { + GET_ON -> it or (1 shl (ps - 1)) + GET_OFF -> it and (masking - (1 shl (ps - 1))) + MV_BACK -> (it * 2) and masking + MV_FORE -> it / 2 + else -> it + } + } + } + + println(trains.distinct().size) + } + } +} + +fun main() { + `소병희_기차가 어둠을 헤치고 은하수를`.getSolution().solution() +} \ No newline at end of file From 26b64a0ab014255bf122b309bdb1da10c9ccbe60 Mon Sep 17 00:00:00 2001 From: bngsh Date: Mon, 10 Oct 2022 19:44:19 +0900 Subject: [PATCH 02/14] =?UTF-8?q?solve:=20=EB=B3=B4=EB=AC=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../byeonghee/\353\263\264\353\254\274.kt" | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 "src/2week/byeonghee/\353\263\264\353\254\274.kt" diff --git "a/src/2week/byeonghee/\353\263\264\353\254\274.kt" "b/src/2week/byeonghee/\353\263\264\353\254\274.kt" new file mode 100644 index 0000000..fbf86f6 --- /dev/null +++ "b/src/2week/byeonghee/\353\263\264\353\254\274.kt" @@ -0,0 +1,37 @@ +package `2week`.byeonghee + +/** + * @접근방법: 하나는 오름차, 하나는 내림차로 정렬 + */ + +import java.io.* + +class `소병희_보물` { + companion object { + fun getSolution() : Solution { + return Solution() + } + } + + class Solution { + private val br = BufferedReader(InputStreamReader(System.`in`)) + + private var N = 0 + private var A = listOf() + private var B = listOf() + var answer = 0 + + fun solution() { + N = br.readLine().toInt() + A = br.readLine().split(" ").map{ it.toInt() }.sorted() + B = br.readLine().split(" ").map{ it.toInt() }.sortedDescending() + + for(i in 0 until N) { answer += A[i] * B[i] } + println(answer) + } + } +} + +fun main() { + `소병희_보물`.getSolution().solution() +} \ No newline at end of file From a78b5dda94fd0bc5ac5b5a79af16618c5f0c75b2 Mon Sep 17 00:00:00 2001 From: bngsh Date: Mon, 10 Oct 2022 19:47:49 +0900 Subject: [PATCH 03/14] =?UTF-8?q?solve:=20=EA=B7=B8=EB=A6=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../byeonghee/\352\267\270\353\246\274.kt" | 78 +++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 "src/2week/byeonghee/\352\267\270\353\246\274.kt" diff --git "a/src/2week/byeonghee/\352\267\270\353\246\274.kt" "b/src/2week/byeonghee/\352\267\270\353\246\274.kt" new file mode 100644 index 0000000..b75c52c --- /dev/null +++ "b/src/2week/byeonghee/\352\267\270\353\246\274.kt" @@ -0,0 +1,78 @@ +package `2week`.byeonghee + +/** + * @접근방법: bfs + */ + +import java.io.* + +class `소병희_그림` { + companion object { + fun getSolution() : Solution { + return Solution() + } + } + + class Solution { + + private val br = BufferedReader(InputStreamReader(System.`in`)) + + var n = 0 + var m = 0 + var canvas = Array(502){ IntArray(502) } + + data class Pos(val r : Int, val c: Int) + private val adjacents = listOf( + Pos(-1, 0), + Pos(0, -1), + Pos(0, 1), + Pos(1, 0) + ) + + var q = ArrayDeque() + + var drawCount = 0 + var drawSize = 0 + var maxDrawSize = 0 + + + fun solution() { + br.readLine().split(" ").run { + n = first().toInt() + m = last().toInt() + } + canvas = Array(n) { br.readLine().split(" ").map{ it.toInt() }.toIntArray() } + + for(i in 0 until n) for(j in 0 until m) { + if (canvas[i][j] == 0) continue + canvas[i][j] = 0 + drawCount++ + drawSize = 1 + + q.addLast(Pos(i, j)) + while(q.isNotEmpty()) { + q.removeFirst().run { + for((dr, dc) in adjacents) { + if (r + dr in 0 until n + && c + dc in 0 until m + && canvas[r + dr][c + dc] == 1 + ) { + drawSize++ + canvas[r + dr][c + dc] = 0 + q.addLast(Pos(r + dr, c + dc)) + } + } + } + } + maxDrawSize = Integer.max(maxDrawSize, drawSize) + } + + println(drawCount) + println(maxDrawSize) + } + } +} + +fun main() { + `소병희_그림`.getSolution().solution() +} \ No newline at end of file From e3e4dfccc93805958bdd562f7971fe7adf175ec8 Mon Sep 17 00:00:00 2001 From: bngsh Date: Mon, 10 Oct 2022 20:20:24 +0900 Subject: [PATCH 04/14] =?UTF-8?q?solve:=20=EB=8B=A8=EC=A7=80=20=EB=B2=88?= =?UTF-8?q?=ED=98=B8=20=EB=B6=99=EC=9D=B4=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...0 \353\266\231\354\235\264\352\270\260.kt" | 73 +++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 "src/2week/byeonghee/\353\213\250\354\247\200 \353\262\210\355\230\270 \353\266\231\354\235\264\352\270\260.kt" diff --git "a/src/2week/byeonghee/\353\213\250\354\247\200 \353\262\210\355\230\270 \353\266\231\354\235\264\352\270\260.kt" "b/src/2week/byeonghee/\353\213\250\354\247\200 \353\262\210\355\230\270 \353\266\231\354\235\264\352\270\260.kt" new file mode 100644 index 0000000..ea90273 --- /dev/null +++ "b/src/2week/byeonghee/\353\213\250\354\247\200 \353\262\210\355\230\270 \353\266\231\354\235\264\352\270\260.kt" @@ -0,0 +1,73 @@ +package `2week`.byeonghee + +/** + * 접근방식: dfs + * 문제를 잘 읽자 + * 반례모음 : https://www.acmicpc.net/board/view/97339 + */ + +import java.io.* + +class `소병희_단지 번호 붙이기` { + companion object { + fun getSolution() : Solution { + return Solution() + } + } + + class Solution { + companion object { + const val BLANK = '0' + const val APART = '1' + } + + private val br = BufferedReader(InputStreamReader(System.`in`)) + + lateinit var apartMap: Array + + var n = 0 + var complexCount = 0 + /** ▽▽ 이걸 IntArray(200)으로 임의로 줬었는데 아무래도 200개를 넘어갔던 것 같다 **/ + private val complexList = mutableListOf() + private val around = listOf( + Pair(-1, 0), + Pair(0, -1), + Pair(0, 1), + Pair(1, 0) + ) + + fun solution() { + n = br.readLine().toInt() + apartMap = Array(n) { br.readLine().toCharArray() } + + for(i in 0 until n) for(j in 0 until n) { + if (apartMap[i][j] == BLANK) continue + + complexList.add(0) + dfs(i, j) + complexCount++ + } + + println(complexCount) + println(complexList.sorted().joinToString("\n")) + } + + private fun dfs(r: Int, c: Int) { + apartMap[r][c] = BLANK + complexList[complexCount]++ + + for((dr, dc) in around) { + if ((r + dr) in 0 until n + && (c + dc) in 0 until n + && apartMap[r + dr][c + dc] == APART + ) { + dfs(r + dr, c + dc) + } + } + } + } +} + +fun main() { + `소병희_단지 번호 붙이기`.getSolution().solution() +} \ No newline at end of file From eb00201772385eb6140ea142cf321d564c3c7cc6 Mon Sep 17 00:00:00 2001 From: bngsh Date: Mon, 10 Oct 2022 20:32:54 +0900 Subject: [PATCH 05/14] =?UTF-8?q?solve:=20NBA=20=EB=86=8D=EA=B5=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../NBA \353\206\215\352\265\254.kt" | 68 +++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 "src/2week/byeonghee/NBA \353\206\215\352\265\254.kt" diff --git "a/src/2week/byeonghee/NBA \353\206\215\352\265\254.kt" "b/src/2week/byeonghee/NBA \353\206\215\352\265\254.kt" new file mode 100644 index 0000000..36be199 --- /dev/null +++ "b/src/2week/byeonghee/NBA \353\206\215\352\265\254.kt" @@ -0,0 +1,68 @@ +package `2week`.byeonghee + +import java.io.* + +class `소병희_NBA 농구` { + companion object { + fun getSolution() : Solution { + return Solution() + } + } + + class Solution { + val br = BufferedReader(InputStreamReader(System.`in`)) + + data class Goal(val team: Int, val time: Int) + val goals = mutableListOf() + + val maxT = 48 * 60 + val winningT = IntArray(2) + var markTeam = 0 + var markTime = 0 + + fun timeToInt(time: String) : Int { + val (m, s) = time.split(":").map { it.first().digitToInt() * 10 + it.last().digitToInt() } + return m * 60 + s + } + + fun intToTime(time: Int) : String { + val m = (time / 60).toString().padStart(2, '0') + val s = (time % 60).toString().padStart(2, '0') + return "$m:$s" + } + + fun teamCount(team: Int) = if (team == 1) 1 else -1 + + fun solution() { + repeat(br.readLine().toInt()) { + br.readLine().split(" ").run { + goals.add(Goal(first().toInt(), timeToInt(last()))) + } + } + goals.sortBy{ it.time } + + for((goalTeam, goalTime) in goals) { + markTime = if (markTeam == 0) goalTime else markTime + markTeam += teamCount(goalTeam) + + if(markTeam == 0) { + winningT[goalTeam % 2] += (goalTime - markTime) + markTime = goalTime + } + } + + if(markTeam > 0) { + winningT[0] += (maxT - markTime) + } + else if (markTeam < 0) { + winningT[1] += (maxT - markTime) + } + + println(winningT.joinToString("\n") { intToTime(it) }) + } + } +} + +fun main() { + `소병희_NBA 농구`.getSolution().solution() +} \ No newline at end of file From 969f86755f621b040ba26f6f2d371bfd04b937a6 Mon Sep 17 00:00:00 2001 From: bngsh Date: Mon, 10 Oct 2022 20:34:42 +0900 Subject: [PATCH 06/14] =?UTF-8?q?solve:=20=EC=99=B8=ED=8C=90=EC=9B=90=20?= =?UTF-8?q?=EC=88=9C=ED=9A=8C=202?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...354\233\220 \354\210\234\355\232\214 2.kt" | 69 +++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 "src/2week/byeonghee/\354\231\270\355\214\220\354\233\220 \354\210\234\355\232\214 2.kt" diff --git "a/src/2week/byeonghee/\354\231\270\355\214\220\354\233\220 \354\210\234\355\232\214 2.kt" "b/src/2week/byeonghee/\354\231\270\355\214\220\354\233\220 \354\210\234\355\232\214 2.kt" new file mode 100644 index 0000000..d97c737 --- /dev/null +++ "b/src/2week/byeonghee/\354\231\270\355\214\220\354\233\220 \354\210\234\355\232\214 2.kt" @@ -0,0 +1,69 @@ +package `2week`.byeonghee + +/** + * 접근 방식: dp + 비트마스킹으로 도전 + * 한계: dp를 뭔지도 잘 모르고 그냥 한 것 같습니다 큐ㅠㅠ + */ + +import java.io.* + +val br = BufferedReader(InputStreamReader(System.`in`)) + +var n = 0 +var complete = 0 +var adjacency = Array(0){ IntArray(0) } +val dp = Array(1 shl 10){ IntArray(10) { -1 } } + +data class Travel(val city: Int, val route: Int) + +fun getBit(city: Int) : Int { + return 1 shl city +} + +fun getBeforeList(route: Int) : List { + val list = mutableListOf() + for(i in 1 until n) { + getBit(i).run { + if ((route and this) != 0) { + list.add(Travel(i, route xor this)) + } + } + } + return list +} + +fun dfs(route: Int, last: Int) : Int { + if (route == 0) return adjacency[0][last] + if (dp[route][last] > -1) return dp[route][last] + + var minLocalCost = Int.MAX_VALUE + + getBeforeList(route).forEach { before -> + if (dp[before.route][before.city] == -1) { + dp[before.route][before.city] = dfs(before.route, before.city) + } + + if (dp[before.route][before.city] > 0 && adjacency[before.city][last] > 0) { + minLocalCost = Integer.min( + minLocalCost, + dp[before.route][before.city] + adjacency[before.city][last] + ) + } + } + + minLocalCost = minLocalCost.let{ if (it == Int.MAX_VALUE) 0 else it } + return minLocalCost +} + +fun main() { + n = br.readLine().toInt() + complete = (1 shl n) - 1 + + adjacency = Array(n) { br.readLine().split(" ").map{ it.toInt() }.toIntArray() } + + for(i in 0 until n) { + dp[0][i] = adjacency[0][i] + } + + println(dfs(complete - 1, 0)) +} \ No newline at end of file From 849e851d5cb56b520ea8342d9f91373083ed7023 Mon Sep 17 00:00:00 2001 From: bngsh Date: Mon, 10 Oct 2022 21:04:03 +0900 Subject: [PATCH 07/14] =?UTF-8?q?fix:=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 --- ...354\233\220 \354\210\234\355\232\214 2.kt" | 98 +++++++++++-------- 1 file changed, 56 insertions(+), 42 deletions(-) diff --git "a/src/2week/byeonghee/\354\231\270\355\214\220\354\233\220 \354\210\234\355\232\214 2.kt" "b/src/2week/byeonghee/\354\231\270\355\214\220\354\233\220 \354\210\234\355\232\214 2.kt" index d97c737..4923f3f 100644 --- "a/src/2week/byeonghee/\354\231\270\355\214\220\354\233\220 \354\210\234\355\232\214 2.kt" +++ "b/src/2week/byeonghee/\354\231\270\355\214\220\354\233\220 \354\210\234\355\232\214 2.kt" @@ -7,63 +7,77 @@ package `2week`.byeonghee import java.io.* -val br = BufferedReader(InputStreamReader(System.`in`)) +class `소병희_외판원 순회 2` { + companion object { + fun getSolution() : Solution { + return Solution() + } + } -var n = 0 -var complete = 0 -var adjacency = Array(0){ IntArray(0) } -val dp = Array(1 shl 10){ IntArray(10) { -1 } } + class Solution { + private val br = BufferedReader(InputStreamReader(System.`in`)) -data class Travel(val city: Int, val route: Int) + private var n = 0 + private var complete = 0 + private var adjacency = Array(0){ IntArray(0) } + private val dp = Array(1 shl 10){ IntArray(10) { -1 } } -fun getBit(city: Int) : Int { - return 1 shl city -} + data class Travel(val city: Int, val route: Int) + + private fun getBit(city: Int) : Int { + return 1 shl city + } -fun getBeforeList(route: Int) : List { - val list = mutableListOf() - for(i in 1 until n) { - getBit(i).run { - if ((route and this) != 0) { - list.add(Travel(i, route xor this)) + private fun getBeforeList(route: Int) : List { + val list = mutableListOf() + for(i in 1 until n) { + getBit(i).run { + if ((route and this) != 0) { + list.add(Travel(i, route xor this)) + } + } } + return list } - } - return list -} -fun dfs(route: Int, last: Int) : Int { - if (route == 0) return adjacency[0][last] - if (dp[route][last] > -1) return dp[route][last] + private fun dfs(route: Int, last: Int) : Int { + if (route == 0) return adjacency[0][last] + if (dp[route][last] > -1) return dp[route][last] - var minLocalCost = Int.MAX_VALUE + var minLocalCost = Int.MAX_VALUE - getBeforeList(route).forEach { before -> - if (dp[before.route][before.city] == -1) { - dp[before.route][before.city] = dfs(before.route, before.city) - } + getBeforeList(route).forEach { before -> + if (dp[before.route][before.city] == -1) { + dp[before.route][before.city] = dfs(before.route, before.city) + } - if (dp[before.route][before.city] > 0 && adjacency[before.city][last] > 0) { - minLocalCost = Integer.min( - minLocalCost, - dp[before.route][before.city] + adjacency[before.city][last] - ) + if (dp[before.route][before.city] > 0 && adjacency[before.city][last] > 0) { + minLocalCost = Integer.min( + minLocalCost, + dp[before.route][before.city] + adjacency[before.city][last] + ) + } + } + + minLocalCost = minLocalCost.let{ if (it == Int.MAX_VALUE) 0 else it } + return minLocalCost } - } - minLocalCost = minLocalCost.let{ if (it == Int.MAX_VALUE) 0 else it } - return minLocalCost -} + fun solution() { + n = br.readLine().toInt() + complete = (1 shl n) - 1 -fun main() { - n = br.readLine().toInt() - complete = (1 shl n) - 1 + adjacency = Array(n) { br.readLine().split(" ").map{ it.toInt() }.toIntArray() } - adjacency = Array(n) { br.readLine().split(" ").map{ it.toInt() }.toIntArray() } + for(i in 0 until n) { + dp[0][i] = adjacency[0][i] + } - for(i in 0 until n) { - dp[0][i] = adjacency[0][i] + println(dfs(complete - 1, 0)) + } } +} - println(dfs(complete - 1, 0)) +fun main() { + `소병희_외판원 순회 2`.getSolution().solution() } \ No newline at end of file From 440aacd7122ac61d34dd2d6c0ab503ca5c4fb966 Mon Sep 17 00:00:00 2001 From: bngsh Date: Mon, 10 Oct 2022 22:37:25 +0900 Subject: [PATCH 08/14] =?UTF-8?q?solve:=20=EC=84=B1=EA=B2=A9=20=EC=9C=A0?= =?UTF-8?q?=ED=98=95=20=EA=B2=80=EC=82=AC=ED=95=98=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...00\354\202\254\355\225\230\352\270\260.kt" | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 "src/2week/byeonghee/\354\204\261\352\262\251 \354\234\240\355\230\225 \352\262\200\354\202\254\355\225\230\352\270\260.kt" diff --git "a/src/2week/byeonghee/\354\204\261\352\262\251 \354\234\240\355\230\225 \352\262\200\354\202\254\355\225\230\352\270\260.kt" "b/src/2week/byeonghee/\354\204\261\352\262\251 \354\234\240\355\230\225 \352\262\200\354\202\254\355\225\230\352\270\260.kt" new file mode 100644 index 0000000..611f604 --- /dev/null +++ "b/src/2week/byeonghee/\354\204\261\352\262\251 \354\234\240\355\230\225 \352\262\200\354\202\254\355\225\230\352\270\260.kt" @@ -0,0 +1,59 @@ +package `2week`.byeonghee + +/** + * @접근방식 : 알파벳순으로 빠른 4개를 posType, 그 반대 유형을 같은 인덱스로 negType에 저장 + * + */ + +class `소병희_성격 유형 검사하기` { + private val scores = IntArray(4) + private val posType = arrayOf('R', 'C', 'J', 'A') + private val negType = arrayOf('T', 'F', 'M', 'N') + + private fun getType(c: Char): Int { + return when(c) { + 'R', 'T' -> 0 + 'F', 'C' -> 1 + 'M', 'J' -> 2 + 'A', 'N' -> 3 + else -> -1 + } + } + + private fun getTypeSign(c: Char): Int { + return when(c) { + in posType -> 1 + in negType -> -1 + else -> 0 + } + } + + private fun getPoint(i: Int) : Int { + return if (i > 4) i - 4 else 4 - i + } + + private fun getPointSign(i : Int): Int { + return if (i < 4) 1 + else if (i > 4) -1 + else 0 + } + + fun solution(surveys: Array, choices: IntArray): String { + for(i in surveys.indices) { + val c = surveys[i].first() + val op = choices[i] + + scores[getType(c)] += getTypeSign(c) * getPointSign(op) * getPoint(op) + } + + val sb = StringBuilder() + for(i in 0 until 4) { + sb.append( + if (scores[i] >= 0) posType[i] + else negType[i] + ) + } + + return sb.toString() + } +} \ No newline at end of file From 14dfab62b7752fb612a7f2c4e0b648d2f1e53964 Mon Sep 17 00:00:00 2001 From: bngsh Date: Thu, 13 Oct 2022 17:30:50 +0900 Subject: [PATCH 09/14] =?UTF-8?q?solve:=20=ED=82=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- "src/3week/byeonghee/\355\202\271.kt" | 86 +++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 "src/3week/byeonghee/\355\202\271.kt" diff --git "a/src/3week/byeonghee/\355\202\271.kt" "b/src/3week/byeonghee/\355\202\271.kt" new file mode 100644 index 0000000..b43e002 --- /dev/null +++ "b/src/3week/byeonghee/\355\202\271.kt" @@ -0,0 +1,86 @@ +package `3week`.byeonghee + +import java.io.* + +class `소병희_킹` { + companion object { + fun getSolution() : Solution { + return Solution() + } + } + + + class Solution { + companion object { + fun Char.toIdx() : Int { + return if (this.isDigit()) (digitToInt() - 1) else code - 'A'.code + } + + fun Int.isInside() : Boolean { + return this in 0 until 8 + } + + + fun Int.toBoard() : Char { + return (this + 'A'.code).toChar() + } + } + + val br = BufferedReader(InputStreamReader(System.`in`)) + + data class Pos(val r: Int, val c: Int) { + operator fun plus(pos: Pos): Pos { + val newR = r + pos.r + val newC = c + pos.c + return Pos(newR, newC) + } + + fun isInside() = r.isInside() && c.isInside() + + override fun toString() : String { + return c.toBoard() + (r + 1).toString() + } + } + + fun solution() { + val kingMoving = mapOf( + Pair("R", Pos(0, 1)), + Pair("L", Pos(0, -1)), + Pair("B", Pos(-1, 0)), + Pair("T", Pos(1, 0)), + Pair("RT", Pos(1, 1)), + Pair("LT", Pos(1, -1)), + Pair("RB", Pos(-1, 1)), + Pair("LB", Pos(-1, -1)) + ) + + val (king, stone, n) = br.readLine().split(" ") + var kingPos = Pos(king[1].toIdx(), king[0].toIdx()) + var stonePos = Pos(stone[1].toIdx(), stone[0].toIdx()) + + val moves = mutableListOf() + repeat(n.toInt()) { + moves.add( kingMoving.getOrDefault(br.readLine(), Pos(0, 0))) + } + + for(move in moves) { + if (kingPos + move == stonePos) { + if ((stonePos + move).isInside()) { + kingPos = stonePos + stonePos += move + } + } + else if ((kingPos + move).isInside()) { + kingPos += move + } + } + + println("$kingPos") + println("$stonePos") + } + } +} + +fun main() { + `소병희_킹`.getSolution().solution() +} \ No newline at end of file From 15c10c4445fedf2e8e258038358cbc9025349c15 Mon Sep 17 00:00:00 2001 From: bngsh Date: Sat, 15 Oct 2022 16:55:13 +0900 Subject: [PATCH 10/14] =?UTF-8?q?solve:=20=EB=9E=9C=EC=84=A0=20=EC=9E=90?= =?UTF-8?q?=EB=A5=B4=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...0 \354\236\220\353\245\264\352\270\260.kt" | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 "src/3week/byeonghee/\353\236\234\354\204\240 \354\236\220\353\245\264\352\270\260.kt" diff --git "a/src/3week/byeonghee/\353\236\234\354\204\240 \354\236\220\353\245\264\352\270\260.kt" "b/src/3week/byeonghee/\353\236\234\354\204\240 \354\236\220\353\245\264\352\270\260.kt" new file mode 100644 index 0000000..654e21d --- /dev/null +++ "b/src/3week/byeonghee/\353\236\234\354\204\240 \354\236\220\353\245\264\352\270\260.kt" @@ -0,0 +1,58 @@ +package `3week`.byeonghee + +import java.io.* + +/** + * 1. Key: 자르는 길이, value: 만들 수 있는 랜선 개수 를 쌍으로 가지는 맵을 아예 만들었었다 + * 2. key가 1부터 2^31 - 1까지 갈 수 있기 때문에 이진탐색을 하면서 key에 대해 value를 계산하는 것이 빠름 + * 3. 2로 바꾸고 나니 key가 int일 필요 없어서 lb, ub, maxLength, mid를 전부 long타입으로 수정 + * 4. 마찬가지로 2로 바꾸고 나니 maxLength가 큰 수여도 괜찮아져서 그냥 제일 긴 랜선 값 할당 + */ + +class `소병희_랜선 자르기` { + companion object { + fun getSolution(): Solution { + return Solution() + } + } + + class Solution { + val br = BufferedReader(InputStreamReader(System.`in`,)) + + var maxLength = 0L + var lans = IntArray(0) +// var searchMap = mapOf() + + var lb = 1L + var ub = 1L + var mid = 1L + + fun solution() { + val (k, n) = br.readLine().split(" ").map { it.toInt() } + lans = IntArray(k) { br.readLine().toInt() } + + maxLength = lans.maxOf { it }.toLong() + //maxLength = Integer.max(lans.minOf { it }, (lans.sumOf { it.toLong() } / n).toInt()) + //searchMap = (1..maxLength).toList().map { len -> len to lans.sumOf { it / len } }.toMap() + + println(bisearch(n)) + } + + fun bisearch(n: Int): Int { + lb = 1 + ub = maxLength + 1 + + while(lb + 1 < ub) { + mid = lb + ((ub - lb) / 2) + if(lans.sumOf { it / mid.toInt() } >= n) lb = mid + else ub = mid + } + + return lb.toInt() + } + } +} + +fun main() { + `소병희_랜선 자르기`.getSolution().solution() +} \ No newline at end of file From 5120dbb6f8bc37985e3695a51ff0c4687b7e1d42 Mon Sep 17 00:00:00 2001 From: bngsh Date: Mon, 17 Oct 2022 16:51:19 +0900 Subject: [PATCH 11/14] =?UTF-8?q?solve:=20=ED=81=AC=EB=A1=9C=EC=8A=A4?= =?UTF-8?q?=EC=9B=8C=EB=93=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...34\354\212\244\354\233\214\353\223\234.kt" | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 "src/3week/byeonghee/\355\201\254\353\241\234\354\212\244\354\233\214\353\223\234.kt" diff --git "a/src/3week/byeonghee/\355\201\254\353\241\234\354\212\244\354\233\214\353\223\234.kt" "b/src/3week/byeonghee/\355\201\254\353\241\234\354\212\244\354\233\214\353\223\234.kt" new file mode 100644 index 0000000..742b35a --- /dev/null +++ "b/src/3week/byeonghee/\355\201\254\353\241\234\354\212\244\354\233\214\353\223\234.kt" @@ -0,0 +1,47 @@ +package `3week`.byeonghee + +/** 우선순위큐, split 함수 */ + +import java.io.* +import java.util.* + +class `소병희_크로스워드` { + companion object { + fun getSolution() : Solution { + return Solution() + } + } + + class Solution { + val br = BufferedReader(InputStreamReader(System.`in`)) + + var words = PriorityQueue { a, b -> when { + a > b -> 1 + a < b -> -1 + else -> 0 + }} + + fun solution() { + val (row, col) = br.readLine().split(" ").map{ it.toInt()} + val puzzles = Array(row) { br.readLine() } + + (0 until row).forEach { r -> + puzzles[r].split("#").filter{ it.length > 1 }.let { + words.addAll(it) + } + } + + (0 until col).forEach { c -> + puzzles.map{ it[c] }.joinToString("").split("#").filter{ it.length > 1 }.let { + words.addAll(it) + } + } + + println(words.peek()) + } + } +} + +fun main() { + `소병희_크로스워드`.getSolution().solution() +} \ No newline at end of file From d5f8f58918ace5e9169f444ffd6efc3a935a8a72 Mon Sep 17 00:00:00 2001 From: bngsh Date: Mon, 17 Oct 2022 19:27:49 +0900 Subject: [PATCH 12/14] =?UTF-8?q?try:=20=EB=8B=A8=ED=92=8D=EC=9E=8E=20?= =?UTF-8?q?=EC=9D=B4=EC=95=BC=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...6 \354\235\264\354\225\274\352\270\260.kt" | 66 +++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 "src/3week/byeonghee/\353\213\250\355\222\215\354\236\216 \354\235\264\354\225\274\352\270\260.kt" diff --git "a/src/3week/byeonghee/\353\213\250\355\222\215\354\236\216 \354\235\264\354\225\274\352\270\260.kt" "b/src/3week/byeonghee/\353\213\250\355\222\215\354\236\216 \354\235\264\354\225\274\352\270\260.kt" new file mode 100644 index 0000000..f30f8db --- /dev/null +++ "b/src/3week/byeonghee/\353\213\250\355\222\215\354\236\216 \354\235\264\354\225\274\352\270\260.kt" @@ -0,0 +1,66 @@ +package `3week`.byeonghee + +import java.io.* + +class `소병희_단풍잎 이야기` { + companion object { + fun getSolution() : Solution { + return Solution() + } + } + + class Solution { + val br = BufferedReader(InputStreamReader(System.`in`)) + + var n = 0 + var m = 0 + + val games = mutableListOf() + val useList = mutableSetOf() + val pickList = mutableSetOf() + var answer = 0 + + fun getBit(n: Int) : Int { + return 1 shl n + } + + fun dfs(bm: Int, pick: Int) { + if (pick == n) { + pickList.add(bm) + return + } + + for(i in useList) { + if (getBit(i) and bm > 0) continue + dfs(bm + getBit(i), pick + 1) + } + } + + + fun solution() { + br.readLine().split(" ").map{ it.toInt() }.let { + n = it[0] + m = it[1] + } + + repeat(m) { + br.readLine().split(" ") + .fold(0) { acc, v -> + useList.add(v.toInt()) + acc + getBit(v.toInt()) + } + .let { games.add(it) } + } + + dfs(0, 0) + + pickList.forEach { bm -> answer = Integer.max(answer, games.count { it and bm == it }) } + + println(answer) + } + } +} + +fun main() { + `소병희_단풍잎 이야기`.getSolution().solution() +} \ No newline at end of file From 76bf5f390a339c8cb8887ed1d898d20887377156 Mon Sep 17 00:00:00 2001 From: bngsh Date: Mon, 17 Oct 2022 20:22:29 +0900 Subject: [PATCH 13/14] =?UTF-8?q?try:=20=EB=8F=84=ED=94=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../byeonghee/\353\217\204\355\224\274.kt" | 74 +++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 "src/3week/byeonghee/\353\217\204\355\224\274.kt" diff --git "a/src/3week/byeonghee/\353\217\204\355\224\274.kt" "b/src/3week/byeonghee/\353\217\204\355\224\274.kt" new file mode 100644 index 0000000..05b45cd --- /dev/null +++ "b/src/3week/byeonghee/\353\217\204\355\224\274.kt" @@ -0,0 +1,74 @@ +package `3week`.byeonghee + +import java.io.* + +class `소병희_도피` { + companion object { + fun getSolution() : Solution { + return Solution() + } + } + + class Solution { + companion object { + const val ONEPROB = 1000000000000000000L + } + + val br = BufferedReader(InputStreamReader(System.`in`)) + + var n = 0 + + var dp = Array(0) { LongArray(0) } + var moves = Array(0) { LongArray(0) } + var ans = 0L + var cityList = mutableListOf() + + fun getDp(day: Int, dst: Int) { + if (dp[day][dst] > -1) return + + var prob = 0L + for(from in 0 until n) { + if(dp[day-1][from] < 0) getDp(day-1, from) + prob += dp[day-1][from] * moves[from][dst] + } + dp[day][dst] = prob + } + + fun solution() { + + val (n_tmp, m) = br.readLine().split(" ").map{ it.toInt() } + n = n_tmp + + dp = Array(9) { LongArray(n){ -1 } } + moves = Array(n) { LongArray(n) } + + repeat(m) { + br.readLine().split(" ").map{ it.toInt() }.let { + moves[it[0]][it[1]] = it[2].toLong() + } + } + + dp[0].fill(0) + moves[0].forEachIndexed { i, v -> dp[0][i] = v } + + for(e in 0 until n) { + getDp(8, e) + if (ans < dp[8][e]) { + ans = dp[8][e] + cityList = mutableListOf(e) + } + else if (ans == dp[8][e]) { + cityList.add(e) + } + } + + println(cityList.joinToString(" ")) + if (ans == ONEPROB) println("1." + "0".repeat(18)) + else println(String.format("0.%18d", ans)) + } + } +} + +fun main() { + `소병희_도피`.getSolution().solution() +} \ No newline at end of file From 24bef7fcdcf2893ab18dcd8f0f93d5935c283ccc Mon Sep 17 00:00:00 2001 From: bngsh Date: Tue, 18 Oct 2022 23:22:03 +0900 Subject: [PATCH 14/14] =?UTF-8?q?try:=20=EB=A7=88=EB=B2=95=EC=82=AC=20?= =?UTF-8?q?=EC=83=81=EC=96=B4=EC=99=80=20=EB=B3=B5=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...4\354\231\200 \353\263\265\354\240\234.kt" | 149 ++++++++++++++++++ 1 file changed, 149 insertions(+) create mode 100644 "src/3week/byeonghee/\353\247\210\353\262\225\354\202\254 \354\203\201\354\226\264\354\231\200 \353\263\265\354\240\234.kt" diff --git "a/src/3week/byeonghee/\353\247\210\353\262\225\354\202\254 \354\203\201\354\226\264\354\231\200 \353\263\265\354\240\234.kt" "b/src/3week/byeonghee/\353\247\210\353\262\225\354\202\254 \354\203\201\354\226\264\354\231\200 \353\263\265\354\240\234.kt" new file mode 100644 index 0000000..0f7dfe8 --- /dev/null +++ "b/src/3week/byeonghee/\353\247\210\353\262\225\354\202\254 \354\203\201\354\226\264\354\231\200 \353\263\265\354\240\234.kt" @@ -0,0 +1,149 @@ +package `3week`.byeonghee + +import java.io.* + +val br = BufferedReader(InputStreamReader(System.`in`)) + +var m = 0 +var s = 0 +var r = 0 +var c = 0 +var d = 0 + +data class Pos(var r: Int, var c: Int) { + operator fun plus(add: Pos): Pos { + return Pos(r + add.r, c + add.c) + } + + fun isIn(): Boolean { + return r in 0 until 4 && c in 0 until 4 + } + + fun flatIdx() : Int { + return r * 4 + c + } +} +data class Fish(var p: Pos, var d: Int) + +val di = arrayOf( + Pos(1, -1), + Pos(1, 0), //하 + Pos(1, 1), + Pos(0, 1), //우 + Pos(-1, 1), + Pos(-1, 0), //상 + Pos(-1, -1), + Pos(0, -1) //좌 +) + +var prevFishCnt = 0 +var curFishCnt = 0 +val prevGrid = IntArray(16) //flatten +val smells = IntArray(16) +val curGrid = IntArray(16) +val fishs = ArrayDeque() +var shark = Pos(0, 0) +val sharkMv = Array(64) { Array(3) { Pos(0, 0) }} +lateinit var newFish: Fish +var canGo = true + + +fun main() { + br.readLine().split(" ").map { it.toInt() }.let { + m = it[0] + s = it[1] + } + + repeat(m) { + br.readLine().split(" ").map { it.toInt() }.let { + fishs.addLast(Fish(Pos(it[0]-1, it[1]-1), 8 - it[2])) + prevGrid[Pos(it[0]-1, it[1]-1).flatIdx()]++ + } + } + + br.readLine().split(" ").map { it.toInt() }.let { + shark.r = it[0] - 1 + shark.c = it[1] - 1 + } + + val dPriority = listOf(5, 7, 1, 3) + var cnt = 0 + + for(f in dPriority) for(s in dPriority) for (t in dPriority) { + sharkMv[cnt++] = arrayOf(di[f], di[f] + di[s], di[f] + di[s] + di[t]) + } + + + var maxCnt = -1 + var tmpCnt: Int + var maxMv = -1 + + for(t in 0 until s) { + // 1, 2번 같이 수행 + prevFishCnt = curFishCnt + curFishCnt = fishs.size + for(i in 0 until fishs.size) { + while (i >= prevFishCnt && smells[fishs[i].p.flatIdx()] == 2) { + fishs.removeAt(i) + curFishCnt-- + if (i == fishs.size) break + } + newFish = fishs[i].copy() + canGo = true + while((newFish.p + di[newFish.d]).isIn().not() + || smells[(newFish.p + di[newFish.d]).flatIdx()] > 0 + || shark == (newFish.p + di[newFish.d])) { + newFish.d = (newFish.d + 1) % 8 + if (newFish.d == fishs[i].d) { + canGo = false + break + } + } + if(canGo) newFish.p += di[newFish.d] + fishs.add(newFish) + curGrid[newFish.p.flatIdx()]++ + } + + //3-1. 상어 이동순서 구하기 + maxCnt = -1 + maxMv = -1 + for(mv in sharkMv.indices) { + if (sharkMv[mv].any { (shark + it).isIn().not() }) continue + + sharkMv[mv].let { + tmpCnt = curGrid[(it[0] + shark).flatIdx()] + tmpCnt += curGrid[(it[1] + shark).flatIdx()] + if (it[2] != it[0]) { + tmpCnt += curGrid[(it[2] + shark).flatIdx()] + } + } + + if (tmpCnt > maxCnt) { + maxCnt = tmpCnt + maxMv = mv + } + } + + //3-2. 상어 잡아먹기 + 냄새 흐려지기 + for(i in 0 until 16) { + if (smells[i] > 0) smells[i]-- + prevGrid[i] += curGrid[i] + } + sharkMv[maxMv].map{ (shark + it).flatIdx() }.forEach { + if (prevGrid[it] > 0) { + smells[it] += 2 + prevGrid[it] -= curGrid[it] + } + } + shark += sharkMv[maxMv][2] + curGrid.fill(0) + } + +// tmpCnt = 0 +// for(i in 0 until 16) { +// if (smells[i] == 2) tmpCnt += prevGrid[i] +// } + +// println(fishs.size - tmpCnt) + println(prevGrid.sumOf { it }) +} \ No newline at end of file