diff --git a/storage/zeta/kt/completed/11057.kt b/storage/zeta/kt/completed/11057.kt new file mode 100644 index 0000000..ae47150 --- /dev/null +++ b/storage/zeta/kt/completed/11057.kt @@ -0,0 +1,29 @@ +const val MOD = 10_007 + +val MEMORY = Array(1003) { IntArray(10) { -1 } } + +fun countUprisingFrom(from: Int /*[0, 9]*/, length: Int): Int { + if (MEMORY[length][from] != -1) { + return MEMORY[length][from] + } + return if (length == 1) { + MEMORY[length][from] = 1 + 1 + } else { + val s = (from..9).fold(0) { total, now -> + (total + countUprisingFrom(now, length - 1)) % MOD + } + MEMORY[length][from] = s + s + } +} + +fun countTotalUprising(length: Int): Int { + return ((0..9).sumOf { countUprisingFrom(it, length) } % MOD) +} + + +fun main() { + val n = readln().toInt() + println(countTotalUprising(n)) +} \ No newline at end of file diff --git a/storage/zeta/kt/completed/15835.kt b/storage/zeta/kt/completed/15835.kt new file mode 100644 index 0000000..7c4ad67 --- /dev/null +++ b/storage/zeta/kt/completed/15835.kt @@ -0,0 +1,66 @@ +import java.io.StreamTokenizer + + +fun find(parents: IntArray, x: Int): Int { + return if (parents[x] == x) { + x + } else { + parents[x] = find(parents, parents[x]) + parents[x] + } +} + +fun union(parents: IntArray, a: Int, b: Int): Boolean { + val ra = find(parents, a) + val rb = find(parents, b) + + if (ra == rb) { + return false + } else if (ra < rb) { + parents[rb] = ra + } else { + parents[ra] = rb + } + return true +} + + +fun minimumDistanceOfExploration(n: Int, edges: List>): Int { + val par = IntArray(n) { it } + var minDist = 0 + edges.sortedBy { it.third }.forEach { + val (a, b, w) = it + if (union(par, a, b)) { + minDist += w + } + } + + return minDist +} + + +fun main() = with(StreamTokenizer(System.`in`.bufferedReader())) { + nextToken() + val t = nval.toInt() + + (1..t).forEach { + nextToken() + val n = nval.toInt() + nextToken() + val m = nval.toInt() + + val edges = (1..m).map { + nextToken() + val s = nval.toInt() - 1 + nextToken() + val e = nval.toInt() - 1 + nextToken() + val w = nval.toInt() + + Triple(s, e, w) + } + + println("Case #${it}: ${minimumDistanceOfExploration(n, edges)} meters") + + } +} \ No newline at end of file diff --git a/storage/zeta/kt/completed/20411.kt b/storage/zeta/kt/completed/20411.kt new file mode 100644 index 0000000..be23708 --- /dev/null +++ b/storage/zeta/kt/completed/20411.kt @@ -0,0 +1,25 @@ +fun main() = with(System.`in`.bufferedReader()) { + val iter = this.readLine().split(" ").iterator() + + val m = iter.next().toLong() + val seed = iter.next().toLong() + val x1 = iter.next().toLong() + val x2 = iter.next().toLong() + + // x1 = (a * seed + c) % m + // x2 = (a * x1 + c) % m + + (0 until m).asSequence().map { a -> + val t = (a * seed) % m + val c = if (t <= x1) { + x1 - t + } else { + m - (t - x1) + } + a to c + }.first { (a, c) -> + x2 == (a * x1 + c) % m + }.let { (a, c) -> + println("$a $c") + } +} \ No newline at end of file diff --git a/storage/zeta/kt/completed/25345.kt b/storage/zeta/kt/completed/25345.kt new file mode 100644 index 0000000..e4b9b0f --- /dev/null +++ b/storage/zeta/kt/completed/25345.kt @@ -0,0 +1,56 @@ +const val MOD = 1_000_000_007 + +val MEM_CHOOSE = Array(2001) { LongArray(2000) { -1 } } +val MEM_POW = LongArray(2001) { -1 } + +fun choose(n: Int, k: Int): Long { + if (MEM_CHOOSE[n][k] != -1L) { + return MEM_CHOOSE[n][k] + } + if (n == 1 || n == 0) { + MEM_CHOOSE[n][k] == 1L + return 1 + } else if (k == 0) { + MEM_CHOOSE[n][k] = 1 + return 1 + } else if (k == 1) { + MEM_CHOOSE[n][k] = n.toLong() + return n.toLong() + } else if (k == n) { + MEM_CHOOSE[n][k] = 1 + return 1 + } else if (k == n - 1) { + MEM_CHOOSE[n][k] = n.toLong() + return n.toLong() + } else { + val res = (choose(n - 1, k - 1) + choose(n - 1, k)) % MOD + MEM_CHOOSE[n][k] = res + return res + } +} + + +fun powOf2(n: Int): Long { + if (MEM_POW[n] != -1L) { + return MEM_POW[n] + } + if (n == 0) { + MEM_POW[n] = 1L + return 1 + } else { + val res = (powOf2(n - 1) * 2) % MOD + MEM_POW[n] = res + return res + } +} + +fun modifier(k: Int): Long { + return powOf2(k - 1) +} + + +fun main() = with(System.`in`.bufferedReader()) { + val (n, k) = this.readLine().split(" ").map { it.toInt() } + // val arr = this.readLine().split(" ").map { it.toInt() } + println(choose(n, k) * modifier(k) % MOD) +} \ No newline at end of file diff --git a/storage/zeta/kt/completed/28242.kt b/storage/zeta/kt/completed/28242.kt new file mode 100644 index 0000000..0d21a42 --- /dev/null +++ b/storage/zeta/kt/completed/28242.kt @@ -0,0 +1,52 @@ +fun divisors(n: Long): List> { + val res = mutableListOf>() + + var i = 1L + + while (i * i <= n) { + if (n % i == 0L) { + res.add(i to n / i) + if (i != n / i) { + res.add(n / i to i) + } + } + i++ + } + + return res +} + + +fun main() { + val n = readln().toLong() + + // nx^2 + (n+1)x -(n+2) + // = (ax+b)(cx+d) + // = acx^2 + (ad + bc)x + bd + + // 다음 조건을 만족하는 a > 0, b, c > 0,d를 구하는 프로그램을 작성하시오. + // n = a * c + // (n+1) = a * d + b * c + // b * d = -(n+2) + + + divisors(n).flatMap { first -> + divisors(n + 2).let { + it.map { + it.first to -it.second + } + it.map { + -it.first to it.second + } + }.map { + first to it + } + }.firstOrNull { (first, second) -> + val (a, c) = first + val (b, d) = second + n + 1 == a * d + b * c + }?.let { (first, second) -> + val (a, c) = first + val (b, d) = second + println("$a $b $c $d") + } ?: println(-1) +} \ No newline at end of file diff --git a/storage/zeta/kt/completed/32628.kt b/storage/zeta/kt/completed/32628.kt new file mode 100644 index 0000000..8e985f3 --- /dev/null +++ b/storage/zeta/kt/completed/32628.kt @@ -0,0 +1,40 @@ +import kotlin.math.max +import kotlin.math.min + +class Bag(items: List) { + val cumulativeWeight: List + + init { + var x = 0L + + cumulativeWeight = listOf(0L) + items.map { + x += it + x + } + } + + fun weight(to: Int): Long { + return cumulativeWeight[to] + } +} + +class BagManager(val n: Int, val bag1: Bag, val bag2: Bag) { + fun smallestBig(k: Int): Long { + return (max(0, k - n)..min(n, k)).map { i -> i to (k - i) }.minOf { (i, j) -> + val w1 = bag1.weight(n - i) + val w2 = bag2.weight(n - j) + max(w1, w2) + } + } + +} + +fun main() = with(System.`in`.bufferedReader()) { + val (n, k) = this.readLine()!!.split(' ').map { it.toInt() } + + val bag1 = Bag(ArrayDeque(this.readLine()!!.split(' ').map { it.toLong() })) + val bag2 = Bag(ArrayDeque(this.readLine()!!.split(' ').map { it.toLong() })) + + val manager = BagManager(n, bag1, bag2) + println(manager.smallestBig(k)) +} \ No newline at end of file