From 8e3b7b4850f74423fc6e05929a389bbf5ae608c3 Mon Sep 17 00:00:00 2001 From: jhg3410 <80373033+jhg3410@users.noreply.github.com> Date: Sun, 3 Sep 2023 19:45:48 +0900 Subject: [PATCH 1/4] =?UTF-8?q?solve=20=EA=B2=B9=EC=B9=98=EB=8A=94=20?= =?UTF-8?q?=EA=B1=B4=20=EC=8B=AB=EC=96=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ... \352\261\264 \354\213\253\354\226\264.kt" | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 "src/main/kotlin/heejik/43week/\352\262\271\354\271\230\353\212\224 \352\261\264 \354\213\253\354\226\264.kt" diff --git "a/src/main/kotlin/heejik/43week/\352\262\271\354\271\230\353\212\224 \352\261\264 \354\213\253\354\226\264.kt" "b/src/main/kotlin/heejik/43week/\352\262\271\354\271\230\353\212\224 \352\261\264 \354\213\253\354\226\264.kt" new file mode 100644 index 00000000..148437d5 --- /dev/null +++ "b/src/main/kotlin/heejik/43week/\352\262\271\354\271\230\353\212\224 \352\261\264 \354\213\253\354\226\264.kt" @@ -0,0 +1,50 @@ +package heejik.`43week` + +import java.io.BufferedReader +import java.io.InputStreamReader +import java.io.StreamTokenizer +import kotlin.math.max +import kotlin.properties.Delegates + +class `겹치는 건 싫어` { + var n by Delegates.notNull() + var k by Delegates.notNull() + lateinit var numbers: List + fun setting() = with(BufferedReader(InputStreamReader(System.`in`))) { + readLine().split(' ').map { it.toInt() }.run { + n = this[0] + k = this[1] + } + numbers = readLine().split(' ').map { it.toInt() } + } + + + fun solve() { + setting() + + var answer = 0 + val stored = ArrayDeque() + val counts = MutableList(100001) { 0 } + + for (number in numbers) { + val numberCount = counts[number] + if (numberCount == k) { + answer = max(answer, stored.size) + while (true) { + val removeNumber = stored.removeFirst() + counts[removeNumber]-- + if (removeNumber == number) break + } + } + stored.add(number) + counts[number]++ + } + answer = max(answer, stored.size) + + println(answer) + } +} + +fun main() { + `겹치는 건 싫어`().solve() +} \ No newline at end of file From 03a7e9bf3550f97f9285d45e78d2d619a012ae91 Mon Sep 17 00:00:00 2001 From: jhg3410 <80373033+jhg3410@users.noreply.github.com> Date: Sun, 3 Sep 2023 19:46:00 +0900 Subject: [PATCH 2/4] =?UTF-8?q?solve=20=EA=B8=B0=ED=83=80=EB=A6=AC?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...00\353\246\254\354\212\244\355\212\270.kt" | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 "src/main/kotlin/heejik/43week/\352\270\260\355\203\200\353\246\254\354\212\244\355\212\270.kt" diff --git "a/src/main/kotlin/heejik/43week/\352\270\260\355\203\200\353\246\254\354\212\244\355\212\270.kt" "b/src/main/kotlin/heejik/43week/\352\270\260\355\203\200\353\246\254\354\212\244\355\212\270.kt" new file mode 100644 index 00000000..8a597db2 --- /dev/null +++ "b/src/main/kotlin/heejik/43week/\352\270\260\355\203\200\353\246\254\354\212\244\355\212\270.kt" @@ -0,0 +1,52 @@ +package heejik.`43week` + +import kotlin.math.max +import kotlin.properties.Delegates + +class 기타리스트 { + + lateinit var differences: MutableList + lateinit var dp: MutableList> + var n by Delegates.notNull() + var s by Delegates.notNull() + var m by Delegates.notNull() + var answer = -1 + + fun solve() { + readln().split(' ').map { it.toInt() }.run { + n = this[0] + s = this[1] + m = this[2] + } + differences = readln().split(' ').map { it.toInt() }.toMutableList() + dp = MutableList(n + 1) { MutableList(m + 1) { false } } + dp[0][s] = true + + play().also { + println(it) + } + } + + private fun play(): Int { + repeat(n) first@{ songIdx -> + repeat(m + 1) second@{ volume -> + if (dp[songIdx][volume].not()) return@second + val plusDiff = volume + differences[songIdx] + val minusDiff = volume - differences[songIdx] + + if (plusDiff in 0..m) { + dp[songIdx + 1][plusDiff] = true + } + if (minusDiff in 0..m) { + dp[songIdx + 1][minusDiff] = true + } + } + } + + return dp[n].lastIndexOf(true) + } +} + +fun main() { + 기타리스트().solve() +} \ No newline at end of file From 7f4e76a7b91802cc722ea25970fcfccbf5d880b7 Mon Sep 17 00:00:00 2001 From: jhg3410 <80373033+jhg3410@users.noreply.github.com> Date: Sun, 3 Sep 2023 19:46:10 +0900 Subject: [PATCH 3/4] =?UTF-8?q?solve=20=EC=89=AC=EC=9A=B4=20=EC=B5=9C?= =?UTF-8?q?=EB=8B=A8=EA=B1=B0=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...34\353\213\250\352\261\260\353\246\254.kt" | 74 +++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 "src/main/kotlin/heejik/43week/\354\211\254\354\232\264 \354\265\234\353\213\250\352\261\260\353\246\254.kt" diff --git "a/src/main/kotlin/heejik/43week/\354\211\254\354\232\264 \354\265\234\353\213\250\352\261\260\353\246\254.kt" "b/src/main/kotlin/heejik/43week/\354\211\254\354\232\264 \354\265\234\353\213\250\352\261\260\353\246\254.kt" new file mode 100644 index 00000000..1a56c5a2 --- /dev/null +++ "b/src/main/kotlin/heejik/43week/\354\211\254\354\232\264 \354\265\234\353\213\250\352\261\260\353\246\254.kt" @@ -0,0 +1,74 @@ +package heejik.`43week` + +import kotlin.properties.Delegates + +class `쉬운 최단거리` { + + val dx = listOf(1, -1, 0, 0) + val dy = listOf(0, 0, 1, -1) + + data class Pos( + val x: Int, + val y: Int + ) + + lateinit var target: Pos + var n by Delegates.notNull() + var m by Delegates.notNull() + val board = mutableListOf>() + + fun solve() = with(System.`in`.bufferedReader()) { + + readLine().split(' ').map { it.toInt() }.run { + n = this[0] + m = this[1] + } + + repeat(n) { + val row = readLine().split(' ').map { + if (it == "1") -1 + else it.toInt() + } + if (row.contains(2)) { + target = Pos(x = it, y = row.indexOf(2)) + } + board.add(row.toMutableList()) + } + + bfs(target.x, target.y) + + val sb = StringBuilder() + repeat(n) { x -> + repeat(m) { y -> + sb.append("${board[x][y]} ") + } + sb.appendLine() + } + + print(sb) + } + + private fun bfs(_x: Int, _y: Int) { + val queue = ArrayDeque() + queue.add(Pos(_x, _y)) + board[_x][_y] = 0 + + while (queue.isNotEmpty()) { + val (x, y) = queue.removeFirst() + for (i in dx.indices) { + val nx = x + dx[i] + val ny = y + dy[i] + if (nx in 0 until n && ny in 0 until m) { + if (board[nx][ny] == -1) { + queue.add(Pos(nx, ny)) + board[nx][ny] = board[x][y] + 1 + } + } + } + } + } +} + +fun main() { + `쉬운 최단거리`().solve() +} From 76dcb9a8dde9ff77dbfc04cd628cb25df90ef534 Mon Sep 17 00:00:00 2001 From: jhg3410 <80373033+jhg3410@users.noreply.github.com> Date: Sun, 3 Sep 2023 19:46:27 +0900 Subject: [PATCH 4/4] =?UTF-8?q?solve=20=ED=9A=8C=EC=A0=84=20=EC=B4=88?= =?UTF-8?q?=EB=B0=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...4\354\240\204 \354\264\210\353\260\245.kt" | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 "src/main/kotlin/heejik/43week/\355\232\214\354\240\204 \354\264\210\353\260\245.kt" diff --git "a/src/main/kotlin/heejik/43week/\355\232\214\354\240\204 \354\264\210\353\260\245.kt" "b/src/main/kotlin/heejik/43week/\355\232\214\354\240\204 \354\264\210\353\260\245.kt" new file mode 100644 index 00000000..b1ca607a --- /dev/null +++ "b/src/main/kotlin/heejik/43week/\355\232\214\354\240\204 \354\264\210\353\260\245.kt" @@ -0,0 +1,39 @@ +package heejik.`43week` + +import kotlin.math.max + +class `회전 초밥` { + + fun solve() = with(System.`in`.bufferedReader()) { + var answer = 0 + + val belt = mutableListOf() + + val (n, d, k, c) = readLine().split(' ').map { it.toInt() } + + repeat(n) { + val sushi = readLine().toInt() + belt.add(sushi) + } + // 맨 뒤에 k - 1 만큼 앞에 놈들 추가 + repeat(k - 1) { + belt.add(belt[it]) + } + + repeat(n) { i -> + val partBeltSet = belt.subList(i, i + k).toSet() + answer = if (partBeltSet.contains(c)) { + max(answer, partBeltSet.size) + } else { + max(answer, partBeltSet.size + 1) + } + } + + println(answer) + } +} + + +fun main() { + `회전 초밥`().solve() +} \ No newline at end of file