From 3207bbb1f069eb430f154b51c0fb58f12790e0ad Mon Sep 17 00:00:00 2001 From: yenru0 Date: Tue, 26 Aug 2025 17:27:25 +0900 Subject: [PATCH] complete 11760.kt 20955.kt --- storage/zeta/kt/completed/11760.kt | 37 ++++++++++++++++++++++++++++ storage/zeta/kt/completed/20955.kt | 39 ++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+) create mode 100644 storage/zeta/kt/completed/11760.kt create mode 100644 storage/zeta/kt/completed/20955.kt diff --git a/storage/zeta/kt/completed/11760.kt b/storage/zeta/kt/completed/11760.kt new file mode 100644 index 0000000..1d11f29 --- /dev/null +++ b/storage/zeta/kt/completed/11760.kt @@ -0,0 +1,37 @@ +fun getMastermindFeedback(n: Int, secret: String, guess: String): Pair { + var r: Int = 0 + var s: Int = 0 + + val secretChecked = BooleanArray(n) { false } + val guessChecked = BooleanArray(n) { false } + + for (i in 0 until n) { + if (secret[i] == guess[i]) { + r++ + secretChecked[i] = true + guessChecked[i] = true + } + } + + for (i in 0 until n) { + for (j in 0 until n) { + if(secret[i] == guess[j] && !secretChecked[i] && !guessChecked[j]) { + secretChecked[i] = true + guessChecked[j] = true + s++ + break + } + } + } + + return r to s +} + + +fun main() = with(System.`in`.bufferedReader()) { + val (n, a, b) = this.readLine().split(" ").let { + Triple(it[0].toInt(), it[1].trim(), it[2].trim()) + } + + println(getMastermindFeedback(n, a, b).toList().joinToString(" ")) +} \ No newline at end of file diff --git a/storage/zeta/kt/completed/20955.kt b/storage/zeta/kt/completed/20955.kt new file mode 100644 index 0000000..7cc3113 --- /dev/null +++ b/storage/zeta/kt/completed/20955.kt @@ -0,0 +1,39 @@ +fun find(parents: IntArray, x: Int): Int { + var node = x + while (parents[node] != node) { + node = parents[node] + } + return node +} + +fun union(parents: IntArray, a: Int, b: Int): Boolean { + val ra = find(parents, a) + val rb = find(parents, b) + if (ra == rb) return false + if (ra > rb) parents[rb] = ra else parents[ra] = rb + return true +} + +fun minimumOperations(n: Int, edges: List>): Int { + val parents = IntArray(n) { it } + var operations = 0 + edges.forEach { (a, b) -> + if (!union(parents, a, b)) { + operations++ + } + } + + val rooted_parents = parents.map { find(parents, it) } + operations += rooted_parents.distinct().size - 1 + return operations +} + + +fun main() = with(System.`in`.bufferedReader()) { + val (n, m) = this.readLine().split(" ").map { it.toInt() } + val synapses: List> = (1..m).map { + this.readLine().split(" ").map { it.toInt() - 1 }.let { (a, b) -> a to b } + } + + println(minimumOperations(n, synapses)) +} \ No newline at end of file