From 97b6fb2901cab8896ef3b5a7c8b28317e046cf0c Mon Sep 17 00:00:00 2001 From: yenru0 Date: Mon, 1 Sep 2025 16:26:33 +0900 Subject: [PATCH] update sungkohan --- storage/sungkohan/kt/2025-div2-D.kt | 16 ++++++ storage/sungkohan/kt/completed/2025-div2-A.kt | 39 +++++++++++++++ storage/sungkohan/kt/completed/2025-div2-B.kt | 29 +++++++++++ storage/sungkohan/kt/completed/2025-div2-C.kt | 45 +++++++++++++++++ storage/sungkohan/kt/completed/2025-div2-E.kt | 49 +++++++++++++++++++ storage/ucpc/kt/2025-1-d.kt | 31 ++++++++++++ 6 files changed, 209 insertions(+) create mode 100644 storage/sungkohan/kt/2025-div2-D.kt create mode 100644 storage/sungkohan/kt/completed/2025-div2-A.kt create mode 100644 storage/sungkohan/kt/completed/2025-div2-B.kt create mode 100644 storage/sungkohan/kt/completed/2025-div2-C.kt create mode 100644 storage/sungkohan/kt/completed/2025-div2-E.kt create mode 100644 storage/ucpc/kt/2025-1-d.kt diff --git a/storage/sungkohan/kt/2025-div2-D.kt b/storage/sungkohan/kt/2025-div2-D.kt new file mode 100644 index 0000000..df12e7a --- /dev/null +++ b/storage/sungkohan/kt/2025-div2-D.kt @@ -0,0 +1,16 @@ +import java.io.StreamTokenizer + +fun main() = with(StreamTokenizer(System.`in`.bufferedReader())) { + nextToken() + val n = nval.toInt() + nextToken() + val m = nval.toInt() + val edges = (1..m).map { + nextToken() + val u = nval.toInt() - 1 + nextToken() + val v = nval.toInt() - 1 + nextToken() + val w = nval.toLong() + } +} \ No newline at end of file diff --git a/storage/sungkohan/kt/completed/2025-div2-A.kt b/storage/sungkohan/kt/completed/2025-div2-A.kt new file mode 100644 index 0000000..9d82948 --- /dev/null +++ b/storage/sungkohan/kt/completed/2025-div2-A.kt @@ -0,0 +1,39 @@ +import java.io.StreamTokenizer + +fun rectanglePermCount(n: Int, table: Array>): Int { + var cnt = 0 + for (r1 in 0 until n) { + for (c1 in 0 until n) { + for (r2 in r1 until n) { + for (c2 in c1 until n) { + val list: MutableList = mutableListOf() + for (i in r1..r2) { + for (j in c1..c2) { + list.add(table[i][j]) + } + } + list.sort() + if (list.withIndex().all { it.index + 1 == it.value }) { + cnt++ + } + } + } + } + } + return cnt +} + +fun main() = with(StreamTokenizer(System.`in`.bufferedReader())) { + nextToken() + val n = nval.toInt() + + val table = Array(n) { Array(n) { 0 } } + for (i in 0 until n) { + for (j in 0 until n) { + nextToken() + table[i][j] = nval.toInt() + } + } + + println(rectanglePermCount(n, table)) +} \ No newline at end of file diff --git a/storage/sungkohan/kt/completed/2025-div2-B.kt b/storage/sungkohan/kt/completed/2025-div2-B.kt new file mode 100644 index 0000000..588c1c8 --- /dev/null +++ b/storage/sungkohan/kt/completed/2025-div2-B.kt @@ -0,0 +1,29 @@ +fun getMaximumEfficientModules(modules: List): List { + val sortedModules = modules.withIndex().sortedBy { it.value } + + var maxEff = sortedModules[modules.size - 1].value * 3 + var curEff = maxEff + var maxBound = modules.size - 1 + for (i in modules.size - 2 downTo 0) { + val delta = 2 * sortedModules[i].value - sortedModules[i + 1].value + curEff += delta + if(curEff > maxEff) { + maxEff = curEff + maxBound = i + } + + } + return sortedModules.slice(maxBound until sortedModules.size).map { + it.index + 1 + } +} + +fun main() = with(System.`in`.bufferedReader()) { + this.readLine() + val modules = this.readLine().split(" ").map { it.toLong() } + + getMaximumEfficientModules(modules).run { + println(this.size) + println(this.joinToString(" ")) + } +} \ No newline at end of file diff --git a/storage/sungkohan/kt/completed/2025-div2-C.kt b/storage/sungkohan/kt/completed/2025-div2-C.kt new file mode 100644 index 0000000..263890e --- /dev/null +++ b/storage/sungkohan/kt/completed/2025-div2-C.kt @@ -0,0 +1,45 @@ +fun main() = with(System.`in`.bufferedReader()) { + val n = this.readLine().toInt() + var locations = Array(n * n) { 0 to 0 } + for (i in 0 until n) { + this.readLine().split(" ").map { it.toInt() }.forEachIndexed { j, v -> + locations[v - 1] = i to j + } + } + + // + + var boxLeftTop = locations[0].first to locations[0].second + var boxRightTop = locations[0].first to locations[0].second + var boxLeftDown = locations[0].first to locations[0].second + var boxRightDown = locations[0].first to locations[0].second + + var cnt = 1 + + for (item in 1 until n * n) { + val row = locations[item].first + val col = locations[item].second + + if (boxLeftTop.first <= row && boxLeftTop.second >= col) { + boxLeftTop = row to col + } + if (boxRightTop.first <= row && boxRightTop.second <= col) { + boxRightTop = row to col + } + if (boxLeftDown.first >= row && boxLeftDown.second >= col) { + boxLeftDown = row to col + } + if (boxRightDown.first >= row && boxRightDown.second <= col) { + boxRightDown = row to col + } + if (boxLeftTop.first == boxRightTop.first && boxLeftDown.first == boxRightDown.first) { + if (boxLeftTop.second == boxLeftDown.second && boxRightTop.second == boxRightDown.second) { + if ((boxRightTop.first - boxLeftDown.first + 1) * (boxRightTop.second - boxLeftDown.second + 1) == item + 1) { + cnt++ + } + } + } + } + + println(cnt) +} \ No newline at end of file diff --git a/storage/sungkohan/kt/completed/2025-div2-E.kt b/storage/sungkohan/kt/completed/2025-div2-E.kt new file mode 100644 index 0000000..b6ab43f --- /dev/null +++ b/storage/sungkohan/kt/completed/2025-div2-E.kt @@ -0,0 +1,49 @@ +import java.util.Stack + +fun countNearestFarRelation(n: Int, edges: Array>>): Long { + val originXor = IntArray(n) + + val deq = Stack>() + deq.add(0 to 0) + while (deq.isNotEmpty()) { + val (now, before) = deq.pop() + + for ((nxt, w) in edges[now]) { + if (nxt == before) { + continue + } else { + originXor[nxt] = originXor[now] xor w + deq.add(nxt to now) + } + } + } + originXor.sort() + var cnt: Long = 0 + var before = -1 + var cntSliced: Long = 0 + for (i in originXor) { + if (i == before) { + cntSliced++ + } else { + cnt += (cntSliced) * (cntSliced - 1) / 2 + before = i + cntSliced = 1 + } + } + cnt += (cntSliced) * (cntSliced - 1) / 2 + + return cnt +} + +fun main() = with(System.`in`.bufferedReader()) { + val n = this.readLine().toInt() + var edges: Array>> = Array(n + 1) { mutableListOf() } + for (i in 0 until (n - 1)) { + val (u, v, w) = this.readLine().split(" ").map { it.toInt() } + edges[u - 1].add(v - 1 to w) + edges[v - 1].add(u - 1 to w) + } + + println(countNearestFarRelation(n, edges)) + +} \ No newline at end of file diff --git a/storage/ucpc/kt/2025-1-d.kt b/storage/ucpc/kt/2025-1-d.kt new file mode 100644 index 0000000..fb80544 --- /dev/null +++ b/storage/ucpc/kt/2025-1-d.kt @@ -0,0 +1,31 @@ +import java.io.StreamTokenizer + +fun calcs(maxCycle: Int, calcs: List>, query: List) { + var sCalcs = calcs.sortedBy { it.first } + + + + +} + + +fun main() = with(StreamTokenizer(System.`in`.bufferedReader())) { + nextToken() + val n = nval.toInt() + nextToken() + val maxCycle = nval.toInt() + + val calcs = (1..n).map { + nextToken() + val s = nval.toInt() + nextToken() + val e = nval.toInt() + Pair(s, e) + } + + val q = nval.toInt() + val times = (1..q).map { + nextToken() + nval.toInt() + } +} \ No newline at end of file