From 28f1088b2b4952fda67a21bcd90c9678307439f1 Mon Sep 17 00:00:00 2001 From: bngsh Date: Sun, 10 Mar 2024 19:22:42 +0900 Subject: [PATCH 1/4] =?UTF-8?q?solve:=20=EC=9E=91=EC=97=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../week53/\354\236\221\354\227\205.kt" | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 "src/main/kotlin/byeonghee/week53/\354\236\221\354\227\205.kt" diff --git "a/src/main/kotlin/byeonghee/week53/\354\236\221\354\227\205.kt" "b/src/main/kotlin/byeonghee/week53/\354\236\221\354\227\205.kt" new file mode 100644 index 00000000..aee9601a --- /dev/null +++ "b/src/main/kotlin/byeonghee/week53/\354\236\221\354\227\205.kt" @@ -0,0 +1,39 @@ +package byeonghee.week53 + +class 소병희_작업 { + companion object { + fun solve() = with(System.`in`.bufferedReader()) { + val (n, m) = readLine().split(" ").map { it.toInt() } + val preJob = Array(n + 1) { ArrayDeque() } + + repeat(m) { + val (pre, cur) = readLine().split(" ").map { it.toInt() } + preJob[cur].add(pre) + } + + val x = readLine().toInt() + var answer = 0 + val visited = BooleanArray(n+1) + val q = ArrayDeque(x) + q.add(x) + visited[x] = true + + while(q.isNotEmpty()) { + val cur = q.removeFirst() + preJob[cur].forEach { + if (visited[it].not()) { + q.add(it) + visited[it] = true + answer++ + } + } + } + + println(answer) + } + } +} + +fun main() { + 소병희_작업.solve() +} \ No newline at end of file From 5f7d6af26be4405a5420904d01e599ddc6f2b400 Mon Sep 17 00:00:00 2001 From: bngsh Date: Sun, 10 Mar 2024 19:42:10 +0900 Subject: [PATCH 2/4] =?UTF-8?q?solve:=20=EA=B5=AC=EA=B0=84=20=ED=95=A9=20?= =?UTF-8?q?=EA=B5=AC=ED=95=98=EA=B8=B0=205?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\352\265\254\355\225\230\352\270\260 5.kt" | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 "src/main/kotlin/byeonghee/week53/\352\265\254\352\260\204 \355\225\251 \352\265\254\355\225\230\352\270\260 5.kt" diff --git "a/src/main/kotlin/byeonghee/week53/\352\265\254\352\260\204 \355\225\251 \352\265\254\355\225\230\352\270\260 5.kt" "b/src/main/kotlin/byeonghee/week53/\352\265\254\352\260\204 \355\225\251 \352\265\254\355\225\230\352\270\260 5.kt" new file mode 100644 index 00000000..5ef8addf --- /dev/null +++ "b/src/main/kotlin/byeonghee/week53/\352\265\254\352\260\204 \355\225\251 \352\265\254\355\225\230\352\270\260 5.kt" @@ -0,0 +1,34 @@ +package byeonghee.week53 + +class 소병희_구간합구하기5 { + companion object { + fun solve() = with(System.`in`.bufferedReader()) { + val (n, m) = readLine().split(" ").map { it.toInt() } + val table = Array(n + 1) { IntArray(n + 1) } + val sb = StringBuilder() + + repeat(n) { i -> + readLine().split(" ").forEachIndexed { j, v -> + table[i+1][j+1] = table[i+1][j] + v.toInt() + } + } + + repeat(n) { i -> + repeat(n) { j -> + table[i+1][j+1] += table[i][j+1] + } + } + + repeat(m) { + val (r1, c1, r2, c2) = readLine().split(" ").map { it.toInt() } + sb.appendLine(table[r2][c2] + table[r1-1][c1-1] - table[r1-1][c2] - table[r2][c1-1]) + } + + println(sb) + } + } +} + +fun main() { + 소병희_구간합구하기5.solve() +} \ No newline at end of file From 8470e2e4e48b0e71f7702c4a638e342448c1744c Mon Sep 17 00:00:00 2001 From: bngsh Date: Sun, 10 Mar 2024 20:20:30 +0900 Subject: [PATCH 3/4] =?UTF-8?q?solve:=20=ED=82=A4=20=EC=88=9C=EC=84=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\355\202\244 \354\210\234\354\204\234.kt" | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 "src/main/kotlin/byeonghee/week53/\355\202\244 \354\210\234\354\204\234.kt" diff --git "a/src/main/kotlin/byeonghee/week53/\355\202\244 \354\210\234\354\204\234.kt" "b/src/main/kotlin/byeonghee/week53/\355\202\244 \354\210\234\354\204\234.kt" new file mode 100644 index 00000000..f338b298 --- /dev/null +++ "b/src/main/kotlin/byeonghee/week53/\355\202\244 \354\210\234\354\204\234.kt" @@ -0,0 +1,46 @@ +package byeonghee.week53 + +class 소병희_키순서 { + companion object { + fun solve() = with(System.`in`.bufferedReader()) { + val (n, m) = readLine().split(" ").map { it.toInt() } + val adj = Array(n) { IntArray(n) } + + repeat(m) { + val (low, high) = readLine().split(" ").map { it.toInt() - 1 } + adj[low][high] = 1 + adj[high][low] = -1 + } + + for(mid in 0 until n) for(a in 0 until n) for(b in 0 until n) { + val compare = adj[a][mid] + adj[mid][b] + when (compare) { + 2 -> { + adj[a][b] = 1 + adj[b][a] = -1 + } + + -2 -> { + adj[a][b] = -1 + adj[b][a] = 1 + } + } + } + + var answer = 0 + for(a in 0 until n) { + var cnt = 1 + for(b in 0 until n) { + if (adj[a][b] != 0) cnt++ + } + if (cnt == n) answer++ + } + + println(answer) + } + } +} + +fun main() { + 소병희_키순서.solve() +} \ No newline at end of file From 6849a1c8be086ce486e7fab7e5303a3f7fafe377 Mon Sep 17 00:00:00 2001 From: bngsh Date: Tue, 12 Mar 2024 23:37:39 +0900 Subject: [PATCH 4/4] =?UTF-8?q?solve:=20=EB=8F=84=EB=84=9B=EA=B3=BC=20?= =?UTF-8?q?=EB=A7=89=EB=8C=80=20=EA=B7=B8=EB=9E=98=ED=94=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...0 \352\267\270\353\236\230\355\224\204.kt" | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 "src/main/kotlin/byeonghee/week53/\353\217\204\353\204\233\352\263\274 \353\247\211\353\214\200 \352\267\270\353\236\230\355\224\204.kt" diff --git "a/src/main/kotlin/byeonghee/week53/\353\217\204\353\204\233\352\263\274 \353\247\211\353\214\200 \352\267\270\353\236\230\355\224\204.kt" "b/src/main/kotlin/byeonghee/week53/\353\217\204\353\204\233\352\263\274 \353\247\211\353\214\200 \352\267\270\353\236\230\355\224\204.kt" new file mode 100644 index 00000000..d9e1f490 --- /dev/null +++ "b/src/main/kotlin/byeonghee/week53/\353\217\204\353\204\233\352\263\274 \353\247\211\353\214\200 \352\267\270\353\236\230\355\224\204.kt" @@ -0,0 +1,27 @@ +package byeonghee.week53 + +class 소병희_도넛과막대그래프 { + fun solution(edges: Array): IntArray { + val answer = IntArray(4) + val inDegree = IntArray(1_000_001) + val outDegree = IntArray(1_000_001) + + for((from, to) in edges) { + outDegree[from]++ + inDegree[to]++ + } + + var v = 1 + while(inDegree[v] > 0 || outDegree[v] > 0) { + if (inDegree[v] == 0 && outDegree[v] >= 2) answer[0] = v + else if (outDegree[v] == 0) answer[2]++ + else if (inDegree[v] >= 2 && outDegree[v] == 2) answer[3]++ + + v++ + } + + answer[1] = outDegree[answer[0]] - answer[2] - answer[3] + + return answer + } +} \ No newline at end of file