From ee20c8e7530e5a5e41585d0ace0811b40f15fb8d Mon Sep 17 00:00:00 2001 From: soopeach Date: Tue, 12 Mar 2024 11:17:57 +0900 Subject: [PATCH 1/5] =?UTF-8?q?feat:=20=ED=95=AD=EC=B2=B4=20=EC=9D=B8?= =?UTF-8?q?=EC=8B=9D=20=EC=B6=94=EA=B0=80?= 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" | 116 ++++++++++++++++++ 1 file changed, 116 insertions(+) create mode 100644 "src/main/kotlin/hyunsoo/54week/\355\225\255\354\262\264 \354\235\270\354\213\235.kt" diff --git "a/src/main/kotlin/hyunsoo/54week/\355\225\255\354\262\264 \354\235\270\354\213\235.kt" "b/src/main/kotlin/hyunsoo/54week/\355\225\255\354\262\264 \354\235\270\354\213\235.kt" new file mode 100644 index 00000000..46903f40 --- /dev/null +++ "b/src/main/kotlin/hyunsoo/54week/\355\225\255\354\262\264 \354\235\270\354\213\235.kt" @@ -0,0 +1,116 @@ +package hyunsoo.`54week` + +import kotlin.system.exitProcess + +/** + * + * <문제> + * [항체 인식](https://www.acmicpc.net/problem/22352) + * + * - 아이디어 + * 영역 별 구분되어있는 모양이 같아야 함. + * 그리고 하나의 영역을 제외하고는 숫자가 같아야 함. + * + * - 트러블 슈팅 + * + */ +class `전현수_항체_인식` { + + private data class Position(val x: Int, val y: Int) + + private val dirs = listOf( + Position(0, -1), + Position(-1, 0), + Position(0, 1), + Position(1, 0), + ) + + private val origin = mutableListOf>() + private val expected = mutableListOf>() + + fun solution() { + + // 두 좌표의 숫자가 다른 경우의 수 + var numDifferentCnt = 0 + + val (n, m) = readln().split(" ").map { it.toInt() } + + repeat(n) { + val row = readln().split(" ").map { it.toInt() } + origin.add(row as MutableList) + } + + repeat(n) { + val row = readln().split(" ").map { it.toInt() } + expected.add(row as MutableList) + } + + for (i in 0 until origin.size) { + for (j in 0 until origin.first().size) { + + val curNumForOrigin = origin[i][j] + val curNumForExpected = expected[i][j] + + if (curNumForOrigin != curNumForExpected) { + numDifferentCnt++ + + if (2 <= numDifferentCnt) { + println("NO") + exitProcess(0) + } + + val visited = Array(n) { + BooleanArray(m) + } + + dfs(curNumForOrigin, curNumForExpected, Position(i, j), origin, visited) + + if (origin.flatten() == expected.flatten()) println("YES") + else println("NO") + exitProcess(0) + } + } + } + + println("YES") + + } + + private fun dfs( + targetNum: Int, + expectNumber: Int, + targetPos: Position, + target: MutableList>, + visited: Array, + ) { + + val curNum = target[targetPos.x][targetPos.y] + + if (targetNum != curNum) return + + visited[targetPos.x][targetPos.y] = true + target[targetPos.x][targetPos.y] = expectNumber + + dirs.forEach { dir -> + + val nx = targetPos.x + dir.x + val ny = targetPos.y + dir.y + + if (nx !in 0 until target.size || + ny !in 0 until target.first().size || + visited[nx][ny] + ) return@forEach + + dfs(targetNum, expectNumber, Position(nx, ny), target, visited) + } + + } + + companion object { + const val CHECKED = -1 + } +} + +fun main() { + 전현수_항체_인식().solution() +} \ No newline at end of file From c596fb17525beddd44f9d7a483d748659818458f Mon Sep 17 00:00:00 2001 From: soopeach Date: Tue, 12 Mar 2024 14:10:33 +0900 Subject: [PATCH 2/5] =?UTF-8?q?feat:=20=ED=86=A0=EB=A7=88=ED=86=A0=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= 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" | 87 +++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 "src/main/kotlin/hyunsoo/54week/\355\206\240\353\247\210\355\206\240.kt" diff --git "a/src/main/kotlin/hyunsoo/54week/\355\206\240\353\247\210\355\206\240.kt" "b/src/main/kotlin/hyunsoo/54week/\355\206\240\353\247\210\355\206\240.kt" new file mode 100644 index 00000000..6037d5d9 --- /dev/null +++ "b/src/main/kotlin/hyunsoo/54week/\355\206\240\353\247\210\355\206\240.kt" @@ -0,0 +1,87 @@ +package hyunsoo.`54week` + +import java.util.LinkedList +import java.util.Queue + +/** + * + * <문제> + * [토마토](https://www.acmicpc.net/problem/7576) + * + * - 아이디어 + * + * - 트러블 슈팅 + * + */ +class `전현수_토마토` { + + private data class Position(val x: Int, val y: Int) + + private val dirs = listOf( + Position(0, -1), + Position(-1, 0), + Position(0, 1), + Position(1, 0), + ) + + private data class QueueData(val pos: Position, val day: Int) + + private val box = mutableListOf>() + private val startPositionList = mutableListOf() + + fun solution() { + + val queue: Queue = LinkedList() + + val (n, m) = readln().split(" ").map { it.toInt() } + + repeat(m) { rowIndex -> + val row = readln().split(" ") + .mapIndexed { columnIndex, it -> + if (it == "1") startPositionList.add(Position(rowIndex, columnIndex)) + it.toInt() + } as MutableList + box.add(row) + } + + startPositionList.forEach { + queue.add(QueueData(it, 1)) + } + + while (queue.isNotEmpty()) { + + val (curPos, curDay) = queue.poll() + + dirs.forEach { dir -> + + val nx = curPos.x + dir.x + val ny = curPos.y + dir.y + + if (nx !in 0 until m || + ny !in 0 until n + ) return@forEach + + if (box[nx][ny] == 0) { + + box[nx][ny] = curDay + 1 + queue.add(QueueData(Position(nx, ny), curDay + 1)) + + } + } + } + + val result = box.flatten() + + if (result.contains(0)) { + println(-1) + } else { + println(result.maxOf { it } - 1) + } + + } + +} + +fun main() { + 전현수_토마토().solution() +} \ No newline at end of file From 1f29f8fb5b0c3a81f85b110884e2c63b1e9f036b Mon Sep 17 00:00:00 2001 From: soopeach Date: Thu, 14 Mar 2024 00:31:36 +0900 Subject: [PATCH 3/5] =?UTF-8?q?feat:=20=EC=9A=B0=EC=B2=B4=EA=B5=AD=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= 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" | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 "src/main/kotlin/hyunsoo/54week/\354\232\260\354\262\264\352\265\255.kt" diff --git "a/src/main/kotlin/hyunsoo/54week/\354\232\260\354\262\264\352\265\255.kt" "b/src/main/kotlin/hyunsoo/54week/\354\232\260\354\262\264\352\265\255.kt" new file mode 100644 index 00000000..84e6d0c7 --- /dev/null +++ "b/src/main/kotlin/hyunsoo/54week/\354\232\260\354\262\264\352\265\255.kt" @@ -0,0 +1,53 @@ +package hyunsoo.`54week` + +/** + * + * <문제> + * [우체국](https://www.acmicpc.net/problem/2141) + * + * - 아이디어 + * + * - 트러블 슈팅 + * + */ +class `전현수_우체국` { + + private data class VillageInfo(val villageNum: Long, val peopleCnt: Long) + + private val villageInfoList = mutableListOf() + + fun solution() { + + var totalPeopleCnt = 0L + var prefixSumOfPeopleCnt = 0L + val n = readln().toInt() + + repeat(n) { + + val (villageNum, peopleCnt) = readln().split(" ").map { it.toLong() } + villageInfoList.add(VillageInfo(villageNum, peopleCnt)) + totalPeopleCnt += peopleCnt + + } + + val mid = if (totalPeopleCnt % 2 == 0L) totalPeopleCnt / 2 else totalPeopleCnt / 2 + 1 + + villageInfoList + .sortedBy { it.villageNum } + .forEach { + + val (vil, curPeopleCnt) = it + + prefixSumOfPeopleCnt += curPeopleCnt + + if (mid <= prefixSumOfPeopleCnt) { + println(vil) + return + } + } + } +} + +fun main() { + 전현수_우체국().solution() +} \ No newline at end of file From cf227e1600bb3b1d239ce43a3f38412d89498fd8 Mon Sep 17 00:00:00 2001 From: soopeach Date: Thu, 14 Mar 2024 18:23:53 +0900 Subject: [PATCH 4/5] =?UTF-8?q?feat:=20=EB=AC=B8=EC=9E=90=EC=97=B4=20?= =?UTF-8?q?=EA=B2=8C=EC=9E=842=20=EC=B6=94=EA=B0=80?= 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" | 98 +++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 "src/main/kotlin/hyunsoo/54week/\353\254\270\354\236\220\354\227\264 \352\262\214\354\236\204 2.kt" diff --git "a/src/main/kotlin/hyunsoo/54week/\353\254\270\354\236\220\354\227\264 \352\262\214\354\236\204 2.kt" "b/src/main/kotlin/hyunsoo/54week/\353\254\270\354\236\220\354\227\264 \352\262\214\354\236\204 2.kt" new file mode 100644 index 00000000..c9bb341f --- /dev/null +++ "b/src/main/kotlin/hyunsoo/54week/\353\254\270\354\236\220\354\227\264 \352\262\214\354\236\204 2.kt" @@ -0,0 +1,98 @@ +package hyunsoo.`54week` + +/** + * + * <문제> + * [문자열 게임 2](https://www.acmicpc.net/problem/20437) + * + * - 아이디어 + * + * - 트러블 슈팅 + * + */ +class `전현수_문자열_게임_2` { + + val br = System.`in`.bufferedReader() + + private data class CharWithIndex(val char: Char, val index: Int) + + fun solution() { + + val t = br.readLine().toInt() + + repeat(t) { + + var firstConditionResult = Int.MAX_VALUE + var secondConditionResult = -1 + + val w = br.readLine() + val k = br.readLine().toInt() + + val alphabetCounter = IntArray(26) + val validCharList = mutableSetOf() + + val validCharInfoList = mutableListOf() + + if (k == 1) { + println("1 1") + return@repeat + } + + w.forEachIndexed { index, char -> + val curCharCnt = ++alphabetCounter[char.toSequence()] + if (k <= curCharCnt) + validCharList.add(char) + } + + w.forEachIndexed { index, char -> + if (validCharList.contains(char)) { + validCharInfoList.add(CharWithIndex(char, index)) + } + } + + val sortedValidCharInfoList = validCharInfoList + .sortedWith( + compareBy { it.char } + .thenBy { it.index } + ) + + for (i in sortedValidCharInfoList.indices) { + + val (target, startIndex) = sortedValidCharInfoList[i] + var targetIncludedCnt = 1 + + for (j in i + 1 until sortedValidCharInfoList.size) { + + val (endTarget, endIndex) = sortedValidCharInfoList[j] + if (target != endTarget) { + break + } + targetIncludedCnt++ + if (k != targetIncludedCnt) continue + + val curLength = endIndex - startIndex + 1 + + if (curLength < firstConditionResult) firstConditionResult = curLength + if (secondConditionResult < curLength) secondConditionResult = curLength + + } + } + + if (firstConditionResult == Int.MAX_VALUE || secondConditionResult == -1) { + println(-1) + } else { + println("$firstConditionResult $secondConditionResult") + } + + } + } + + private fun Char.toSequence(): Int { + return this.code - 97 + } + +} + +fun main() { + 전현수_문자열_게임_2().solution() +} \ No newline at end of file From 1ea3478522cda410b8b190e74c50b777e0dcab62 Mon Sep 17 00:00:00 2001 From: soopeach Date: Fri, 15 Mar 2024 17:50:53 +0900 Subject: [PATCH 5/5] =?UTF-8?q?feat:=20=ED=95=AD=EC=B2=B4=20=EC=9D=B8?= =?UTF-8?q?=EC=8B=9D=20=EC=BD=94=EB=93=9C=20=EA=B0=9C=EC=84=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\225\255\354\262\264 \354\235\270\354\213\235.kt" | 12 ------------ 1 file changed, 12 deletions(-) diff --git "a/src/main/kotlin/hyunsoo/54week/\355\225\255\354\262\264 \354\235\270\354\213\235.kt" "b/src/main/kotlin/hyunsoo/54week/\355\225\255\354\262\264 \354\235\270\354\213\235.kt" index 46903f40..98b07ac9 100644 --- "a/src/main/kotlin/hyunsoo/54week/\355\225\255\354\262\264 \354\235\270\354\213\235.kt" +++ "b/src/main/kotlin/hyunsoo/54week/\355\225\255\354\262\264 \354\235\270\354\213\235.kt" @@ -30,9 +30,6 @@ class `전현수_항체_인식` { fun solution() { - // 두 좌표의 숫자가 다른 경우의 수 - var numDifferentCnt = 0 - val (n, m) = readln().split(" ").map { it.toInt() } repeat(n) { @@ -52,12 +49,6 @@ class `전현수_항체_인식` { val curNumForExpected = expected[i][j] if (curNumForOrigin != curNumForExpected) { - numDifferentCnt++ - - if (2 <= numDifferentCnt) { - println("NO") - exitProcess(0) - } val visited = Array(n) { BooleanArray(m) @@ -106,9 +97,6 @@ class `전현수_항체_인식` { } - companion object { - const val CHECKED = -1 - } } fun main() {