update sungkohan
This commit is contained in:
16
storage/sungkohan/kt/2025-div2-D.kt
Normal file
16
storage/sungkohan/kt/2025-div2-D.kt
Normal file
@@ -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()
|
||||||
|
}
|
||||||
|
}
|
||||||
39
storage/sungkohan/kt/completed/2025-div2-A.kt
Normal file
39
storage/sungkohan/kt/completed/2025-div2-A.kt
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
import java.io.StreamTokenizer
|
||||||
|
|
||||||
|
fun rectanglePermCount(n: Int, table: Array<Array<Int>>): 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<Int> = 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))
|
||||||
|
}
|
||||||
29
storage/sungkohan/kt/completed/2025-div2-B.kt
Normal file
29
storage/sungkohan/kt/completed/2025-div2-B.kt
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
fun getMaximumEfficientModules(modules: List<Long>): List<Int> {
|
||||||
|
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(" "))
|
||||||
|
}
|
||||||
|
}
|
||||||
45
storage/sungkohan/kt/completed/2025-div2-C.kt
Normal file
45
storage/sungkohan/kt/completed/2025-div2-C.kt
Normal file
@@ -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)
|
||||||
|
}
|
||||||
49
storage/sungkohan/kt/completed/2025-div2-E.kt
Normal file
49
storage/sungkohan/kt/completed/2025-div2-E.kt
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
import java.util.Stack
|
||||||
|
|
||||||
|
fun countNearestFarRelation(n: Int, edges: Array<MutableList<Pair<Int, Int>>>): Long {
|
||||||
|
val originXor = IntArray(n)
|
||||||
|
|
||||||
|
val deq = Stack<Pair<Int, Int>>()
|
||||||
|
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<MutableList<Pair<Int, Int>>> = 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))
|
||||||
|
|
||||||
|
}
|
||||||
31
storage/ucpc/kt/2025-1-d.kt
Normal file
31
storage/ucpc/kt/2025-1-d.kt
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
import java.io.StreamTokenizer
|
||||||
|
|
||||||
|
fun calcs(maxCycle: Int, calcs: List<Pair<Int, Int>>, query: List<Int>) {
|
||||||
|
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()
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user