From 7cdaf3032aa66250272aeb039be9150c35256535 Mon Sep 17 00:00:00 2001 From: bngsh Date: Mon, 15 Jan 2024 22:15:29 +0900 Subject: [PATCH 1/4] =?UTF-8?q?solve:=20=EC=86=8C=EA=B0=80=20=EA=B8=B8?= =?UTF-8?q?=EC=9D=84=20=EA=B1=B4=EB=84=88=EA=B0=84=20=EC=9D=B4=EC=9C=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...0\352\260\204 \354\235\264\354\234\240.kt" | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 "src/main/kotlin/byeonghee/week51/\354\206\214\352\260\200 \352\270\270\354\235\204 \352\261\264\353\204\210\352\260\204 \354\235\264\354\234\240.kt" diff --git "a/src/main/kotlin/byeonghee/week51/\354\206\214\352\260\200 \352\270\270\354\235\204 \352\261\264\353\204\210\352\260\204 \354\235\264\354\234\240.kt" "b/src/main/kotlin/byeonghee/week51/\354\206\214\352\260\200 \352\270\270\354\235\204 \352\261\264\353\204\210\352\260\204 \354\235\264\354\234\240.kt" new file mode 100644 index 00000000..cada9e30 --- /dev/null +++ "b/src/main/kotlin/byeonghee/week51/\354\206\214\352\260\200 \352\270\270\354\235\204 \352\261\264\353\204\210\352\260\204 \354\235\264\354\234\240.kt" @@ -0,0 +1,24 @@ +package byeonghee.week51 + +class 소병희_소가길을건너간이유 { + companion object { + fun solve() = with(System.`in`.bufferedReader()) { + val n = readLine().toInt() + val cows = IntArray(11) { -1 } + var ans = 0 + + repeat(n) { + val (num, pos) = readLine().split(" ").map { it.toInt() } + + if (cows[num] != -1 && cows[num] != pos) ans++ + cows[num] = pos + } + + println(ans) + } + } +} + +fun main() { + 소병희_소가길을건너간이유.solve() +} \ No newline at end of file From 114dec434ac3d4cdcf43aca53307005a23dabd1a Mon Sep 17 00:00:00 2001 From: bngsh Date: Sun, 25 Feb 2024 16:20:15 +0900 Subject: [PATCH 2/4] =?UTF-8?q?solve:=20=EB=AF=BC=EA=B2=B8=20=EC=88=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\353\257\274\352\262\270 \354\210\230.kt" | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 "src/main/kotlin/byeonghee/week51/\353\257\274\352\262\270 \354\210\230.kt" diff --git "a/src/main/kotlin/byeonghee/week51/\353\257\274\352\262\270 \354\210\230.kt" "b/src/main/kotlin/byeonghee/week51/\353\257\274\352\262\270 \354\210\230.kt" new file mode 100644 index 00000000..4b123a5a --- /dev/null +++ "b/src/main/kotlin/byeonghee/week51/\353\257\274\352\262\270 \354\210\230.kt" @@ -0,0 +1,55 @@ +package byeonghee.week51 + +class 소병희_민겸수 { + companion object { + fun solve() { + fun solve() = with(System.`in`.bufferedReader()) { + var cntM = 0 + val sbMax = StringBuilder() + val sbMin = StringBuilder() + + readLine().forEach { c -> + when(c) { + 'M' -> { + cntM++ + } + 'K' -> { + sbMax.append(5) + + if (cntM-- > 0) { + sbMax.append(0) + sbMin.append(1) + } + + repeat(cntM) { + sbMax.append(0) + sbMin.append(0) + } + + sbMin.append(5) + + cntM = 0 + } + } + } + + if (cntM-- > 0) { + sbMax.append(1) + sbMin.append(1) + } + + repeat(cntM) { + sbMax.append(1) + sbMin.append(0) + } + + println(sbMax) + println(sbMin) + } + } + } +} + +fun main() { + 소병희_민겸수.solve() +} \ No newline at end of file From 20ff4932ac8ece8edce932b134531df0087f7cd1 Mon Sep 17 00:00:00 2001 From: bngsh Date: Sun, 25 Feb 2024 17:32:03 +0900 Subject: [PATCH 3/4] =?UTF-8?q?solve:=20=EC=9D=B4=EB=AA=A8=ED=8B=B0?= =?UTF-8?q?=EC=BD=98=20=ED=95=A0=EC=9D=B8=ED=96=89=EC=82=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...40\354\235\270\355\226\211\354\202\254.kt" | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 "src/main/kotlin/byeonghee/week51/\354\235\264\353\252\250\355\213\260\354\275\230 \355\225\240\354\235\270\355\226\211\354\202\254.kt" diff --git "a/src/main/kotlin/byeonghee/week51/\354\235\264\353\252\250\355\213\260\354\275\230 \355\225\240\354\235\270\355\226\211\354\202\254.kt" "b/src/main/kotlin/byeonghee/week51/\354\235\264\353\252\250\355\213\260\354\275\230 \355\225\240\354\235\270\355\226\211\354\202\254.kt" new file mode 100644 index 00000000..6ee5251b --- /dev/null +++ "b/src/main/kotlin/byeonghee/week51/\354\235\264\353\252\250\355\213\260\354\275\230 \355\225\240\354\235\270\355\226\211\354\202\254.kt" @@ -0,0 +1,58 @@ +package byeonghee.week51 + +class 소병희_이모티콘할인행사 { + + val answer = IntArray(2) + val discounts = 10..40 step 10 + + lateinit var users: Array + lateinit var emoticons: IntArray + + fun solution(_users: Array, _emoticons: IntArray): IntArray { + users = _users + emoticons = _emoticons + + recursiveDiscount(0, IntArray(users.size)) + + return answer + } + + fun recursiveDiscount(idx: Int, shopped: IntArray) { + if (idx == emoticons.size) { + var plus = 0 + var gain = 0 + + for(bill in shopped) { + if (bill == -1) plus++ + else gain += bill + } + + if (answer[0] < plus) { + answer[0] = plus + answer[1] = gain + } + else if (answer[0] == plus && answer[1] < gain) { + answer[1] = gain + } + return + } + + for(discount in discounts) { + var newPrice = emoticons[idx] / 100 * (100 - discount) + val newShopped = shopped.clone() + + for((user, data) in users.withIndex()) { + val (ratio, budget) = data + if (shopped[user] == -1) continue + if (discount >= ratio) { + newShopped[user] += newPrice + if (newShopped[user] >= budget) { + newShopped[user] = -1 + } + } + } + + recursiveDiscount(idx + 1, newShopped) + } + } +} \ No newline at end of file From 45d507ddc76105377ea3f15a560c978492e62c9f Mon Sep 17 00:00:00 2001 From: bngsh Date: Sun, 25 Feb 2024 18:02:26 +0900 Subject: [PATCH 4/4] =?UTF-8?q?solve:=20=EC=98=81=EC=83=81=EC=B2=98?= =?UTF-8?q?=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...01\354\203\201\354\262\230\353\246\254.kt" | 68 +++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 "src/main/kotlin/byeonghee/week51/\354\230\201\354\203\201\354\262\230\353\246\254.kt" diff --git "a/src/main/kotlin/byeonghee/week51/\354\230\201\354\203\201\354\262\230\353\246\254.kt" "b/src/main/kotlin/byeonghee/week51/\354\230\201\354\203\201\354\262\230\353\246\254.kt" new file mode 100644 index 00000000..ac9e6c32 --- /dev/null +++ "b/src/main/kotlin/byeonghee/week51/\354\230\201\354\203\201\354\262\230\353\246\254.kt" @@ -0,0 +1,68 @@ +package byeonghee.week51 + +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 screen = Array(n) { IntArray(m) } + val visited = Array(n) { BooleanArray(m) } + var stuff = 0 + + repeat(n) { i -> + val line = readLine().split(" ").map { it.toInt() } + repeat(m) { j -> + screen[i][j] = (line[j*3] + line[j*3 + 1] + line[j*3 + 2]) / 3 + } + } + + val t = readLine().toInt() + + for(i in 0 until n) for(j in 0 until m) { + screen[i][j] = if (screen[i][j] >= t) 255 else 0 + } + + fun bfs(i: Int, j: Int) { + val q = ArrayDeque() + q.add(intArrayOf(i, j)) + screen[i][j] = stuff + + 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 + visited[nr][nc] = true + + if(screen[nr][nc] == 255) { + screen[nr][nc] = stuff + q.add(intArrayOf(nr, nc)) + } + } + } + } + + for(i in 0 until n) for(j in 0 until m) { + if (visited[i][j]) continue + visited[i][j] = true + + if (screen[i][j] == 255) { + stuff++ + bfs(i, j) + } + } + + println(stuff) + } + } +} + +fun main() { + 소병희_영상처리.solve() +} \ No newline at end of file