From 6754bdcb56e7ddcc6973671b5b0fa0f2697fd39d Mon Sep 17 00:00:00 2001 From: jhg3410 <80373033+jhg3410@users.noreply.github.com> Date: Sun, 16 Oct 2022 19:44:30 +0900 Subject: [PATCH 1/5] =?UTF-8?q?solve:=20=EA=B0=80=EB=A1=9C=EC=88=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\352\260\200\353\241\234\354\210\230.kt" | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 "src/main/kotlin/heejik/5week/\352\260\200\353\241\234\354\210\230.kt" diff --git "a/src/main/kotlin/heejik/5week/\352\260\200\353\241\234\354\210\230.kt" "b/src/main/kotlin/heejik/5week/\352\260\200\353\241\234\354\210\230.kt" new file mode 100644 index 00000000..7d74ab17 --- /dev/null +++ "b/src/main/kotlin/heejik/5week/\352\260\200\353\241\234\354\210\230.kt" @@ -0,0 +1,36 @@ +package heejik.`5week` + +fun main() { + + val n = readln().toInt() + val tree = mutableListOf() + val diff = mutableListOf() + var gcd = 1 + + repeat(n) { + val location = readln().toInt() + if (tree.isNotEmpty()) { + diff.add(location - tree.last()) + } + tree.add(location) + } + + gcd = getGcd(diff[0], diff[1]) + for (i in 2 until diff.size) { + gcd = getGcd(gcd,diff[i]) + } + + println(((tree.last() - tree.first()) / gcd) + 1 - tree.size) + +} + +fun getGcd(_a: Int, _b: Int): Int { + var a = _a + var b = _b + while (b > 0) { + val tmp = a + a = b + b = tmp % b + } + return a +} \ No newline at end of file From 65e90f30677b29824e08d69dfa661d338334a323 Mon Sep 17 00:00:00 2001 From: jhg3410 <80373033+jhg3410@users.noreply.github.com> Date: Sun, 16 Oct 2022 19:44:40 +0900 Subject: [PATCH 2/5] =?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" | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 "src/main/kotlin/heejik/5week/\353\236\234\354\204\240 \354\236\220\353\245\264\352\270\260.kt" diff --git "a/src/main/kotlin/heejik/5week/\353\236\234\354\204\240 \354\236\220\353\245\264\352\270\260.kt" "b/src/main/kotlin/heejik/5week/\353\236\234\354\204\240 \354\236\220\353\245\264\352\270\260.kt" new file mode 100644 index 00000000..c180ee78 --- /dev/null +++ "b/src/main/kotlin/heejik/5week/\353\236\234\354\204\240 \354\236\220\353\245\264\352\270\260.kt" @@ -0,0 +1,46 @@ +package heejik.`5week` + +import java.io.BufferedReader +import java.io.InputStreamReader +import kotlin.system.exitProcess + +val lines = mutableListOf() + +fun main(): Unit = with(BufferedReader(InputStreamReader(System.`in`))) { + var answer = 0L + val (k, n) = readLine().split(' ').map { it.toInt() } + var s = 0L + + repeat(k) { + val line = readLine().toLong() + lines.add(line) + s += line + } + + var start = 0L + var end = s / n + if (end == 1L) { + println(1) + exitProcess(0) + } + while (start <= end) { + val mid = (end + start) / 2 + val cnt = isCorrect(mid) + if (cnt >= n) { + answer = mid + start = mid + 1 + } else { + end = mid - 1 + } + } + + println(answer) +} + +fun isCorrect(length: Long): Long { + var cnt = 0L + lines.forEach { + cnt += it / length + } + return cnt +} \ No newline at end of file From 34ae446c27c549f4b686b68941a7817d09811fda Mon Sep 17 00:00:00 2001 From: jhg3410 <80373033+jhg3410@users.noreply.github.com> Date: Sun, 16 Oct 2022 19:44:47 +0900 Subject: [PATCH 3/5] =?UTF-8?q?solve:=20=EB=B0=94=EB=8B=A5=20=EC=9E=A5?= =?UTF-8?q?=EC=8B=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...4\353\213\245 \354\236\245\354\213\235.kt" | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 "src/main/kotlin/heejik/5week/\353\260\224\353\213\245 \354\236\245\354\213\235.kt" diff --git "a/src/main/kotlin/heejik/5week/\353\260\224\353\213\245 \354\236\245\354\213\235.kt" "b/src/main/kotlin/heejik/5week/\353\260\224\353\213\245 \354\236\245\354\213\235.kt" new file mode 100644 index 00000000..f2f29182 --- /dev/null +++ "b/src/main/kotlin/heejik/5week/\353\260\224\353\213\245 \354\236\245\354\213\235.kt" @@ -0,0 +1,26 @@ +package heejik.`5week` + +fun main() { + var answer = 0 + + val (n, m) = readln().split(' ').map { it.toInt() } + + val floor = arrayListOf().apply { + repeat(n) { + add(readln()) + } + } + + repeat(n) { i -> + answer += floor[i].split('|').filter { it.isNotEmpty() }.size + } + repeat(m) { j -> + var tmp = "" + repeat(n) { i -> + tmp += floor[i][j] + } + answer += tmp.split('-').filter { it.isNotEmpty() }.size + } + + println(answer) +} \ No newline at end of file From ac30d7553375526a1b87b35c7fa621618d00e55a Mon Sep 17 00:00:00 2001 From: jhg3410 <80373033+jhg3410@users.noreply.github.com> Date: Sun, 16 Oct 2022 19:44:54 +0900 Subject: [PATCH 4/5] =?UTF-8?q?solve:=20=EB=B9=99=EA=B3=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../heejik/5week/\353\271\231\352\263\240.kt" | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 "src/main/kotlin/heejik/5week/\353\271\231\352\263\240.kt" diff --git "a/src/main/kotlin/heejik/5week/\353\271\231\352\263\240.kt" "b/src/main/kotlin/heejik/5week/\353\271\231\352\263\240.kt" new file mode 100644 index 00000000..258e6fe1 --- /dev/null +++ "b/src/main/kotlin/heejik/5week/\353\271\231\352\263\240.kt" @@ -0,0 +1,67 @@ +package heejik.`5week` + +import kotlin.system.exitProcess + +val bingo = arrayListOf>() + +fun main() { + var cnt = 0 + var bingoCnt = 0 + val chairMan = arrayListOf>() + + repeat(5) { + bingo.add(readln().split(' ').map { it.toInt() }.toMutableList()) + } + repeat(5) { + chairMan.add(readln().split(' ').map { it.toInt() }.toMutableList()) + } + + chairMan.forEachIndexed { _, ints -> + ints.forEachIndexed { _, num -> + bingo.forEachIndexed { _, row -> + if (num in row) { + cnt += 1 + row[row.indexOf(num)] = -1 + if (isBingo() >= 3) { + println(cnt) + exitProcess(0) + } + bingoCnt = 0 + } + } + } + } +} + +fun isBingo(): Int { + var cnt = 0 + var tmp = 0 + repeat(5) { i -> + if (bingo[i].filter { it == -1 }.size == 5) cnt += 1 + } + + repeat(5) { j -> + tmp = 0 + repeat(5) { i -> + if (bingo[i][j] == -1) { + tmp += 1 + } + if (tmp == 5) cnt += 1 + } + } + + tmp = 0 + repeat(5) { i -> + if (bingo[i][i] == -1) tmp += 1 + } + if (tmp == 5) cnt += 1 + + tmp = 0 + repeat(5) { i -> + if (bingo[i][4 - i] == -1) tmp += 1 + } + if (tmp == 5) cnt += 1 + + return cnt +} + From 386cd21114cb5d4b83c6e3e07209df7305905a8f Mon Sep 17 00:00:00 2001 From: jhg3410 <80373033+jhg3410@users.noreply.github.com> Date: Sun, 16 Oct 2022 19:45:00 +0900 Subject: [PATCH 5/5] =?UTF-8?q?solve:=20=ED=82=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/kotlin/heejik/5week/\355\202\271.kt" | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 "src/main/kotlin/heejik/5week/\355\202\271.kt" diff --git "a/src/main/kotlin/heejik/5week/\355\202\271.kt" "b/src/main/kotlin/heejik/5week/\355\202\271.kt" new file mode 100644 index 00000000..c9b7e26c --- /dev/null +++ "b/src/main/kotlin/heejik/5week/\355\202\271.kt" @@ -0,0 +1,44 @@ +package heejik.`5week` + + +val y = listOf('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H') +val move = listOf("R", "L", "B", "T", "RT", "LT", "RB", "LB") +val dx = listOf(0, 0, -1, 1, 1, 1, -1, -1) +val dy = listOf(1, -1, 0, 0, 1, -1, 1, -1) + +fun main() { + + var (king, rock, n) = readln().split(' ') + + repeat(n.toInt()) { + val location = move.indexOf(readln()) + + var kingX = (king[1].digitToInt()) - 1 + var kingY = y.indexOf(king[0]) + + var rockX = (rock[1].digitToInt()) - 1 + var rockY = y.indexOf(rock[0]) + + val kingNx = kingX + dx[location] + val kingNy = kingY + dy[location] + + + if ((kingNx in 0..7 && kingNy in 0..7).not()) return@repeat + + if (kingNx == rockX && kingNy == rockY) { + val rockNx = rockX + dx[location] + val rockNy = rockY + dy[location] + if ((rockNx in 0..7 && rockNy in 0..7).not()) return@repeat + rockX = rockNx + rockY = rockNy + } + kingX = kingNx + kingY = kingNy + + king = (y[kingY].toString()) + (kingX + 1).toString() + rock = (y[rockY].toString()) + (rockX + 1).toString() + + } + println(king) + println(rock) +} \ No newline at end of file