restructure zeta/** to storage/zeta/**

This commit is contained in:
2025-05-10 21:54:24 +09:00
parent 2886820691
commit 2f2e0759fd
407 changed files with 7 additions and 1 deletions

View File

@@ -0,0 +1,34 @@
import kotlin.text.toInt
operator fun Pair<Int, Int>.plus(b: Pair<Int, Int>) = Pair<Int, Int>(first + b.first, second + b.second)
val Mem = Array<Pair<Int, Int>>(50) { idx ->
if (idx == 0) {
Pair<Int, Int>(1, 0)
} else if (idx == 1) {
Pair<Int, Int>(0, 1)
} else {
Pair<Int, Int>(0, 0)
}
}
fun getFib(n: Int): Pair<Int, Int> {
val m = Mem[n];
if (m.first == 0 && m.second == 0) {
Mem[n] = getFib(n - 1) + getFib(n - 2)
return Mem[n]
} else {
return m;
}
}
fun main() {
val T = readLine()!!.toInt()
for (i in 1..T) {
val N = readLine()!!.toInt()
println(getFib(N).toList().joinToString(" "))
}
}

View File

@@ -0,0 +1,3 @@
fun main() {
println(readLine()?.split(",")?.size)
}

View File

@@ -0,0 +1,34 @@
import kotlin.math.min
fun solve(N: Int, W: Array<Array<Int>>): Int {
val D = ArrayDeque<Triple<Int, Int, Array<Int>>>() // now, cost, visited
D.addLast(Triple(0, 0, Array(N) { 0 }.also { it[0] = 1 }))
var min_cost = Int.MAX_VALUE
while (D.isNotEmpty()) {
val (now, cost, visited) = D.removeLast()
if (visited.all { it == 1 }) {
if (W[now][0] > 0) min_cost = min(min_cost, cost + W[now][0])
continue
} else {
for (i in 1 until N) {
if (visited[i] == 0 && W[now][i] > 0) {
D.addLast(Triple(i, W[now][i] + cost, visited.copyOf().also { it[i] = 1 }))
}
}
}
}
return min_cost
}
fun main() {
val N = readln().toInt()
val W = Array<Array<Int>>(N) { // 0 to N-1
readln().split(' ').map(String::toInt).toTypedArray()
}
println(solve(N, W))
}

View File

@@ -0,0 +1,18 @@
import kotlin.math.max
val Mem = Array<Long>(101) { 0 }
fun solve(N: Int): Long {
for (i in 1..N) {
Mem[i] = Mem[i - 1] + 1
for (j in 3 until i) {
Mem[i] = max(Mem[i], Mem[i - j] * (j - 1))
}
}
return Mem[N]
}
fun main() {
val N = readln().toInt()
println(solve(N))
}

View File

@@ -0,0 +1,32 @@
import kotlin.math.min
fun List<Int>.toTriple(): Triple<Int, Int, Int> {
return Triple(this[0], this[1], this[2])
}
fun solve(N: Int, C: Array<Triple<Int, Int, Int>>): Int {
val T = Array<Triple<Int, Int, Int>>(N) { Triple(0, 0, 0) }
T[0] = C[0]
for (i in 1 until N) {
T[i] = Triple(
min(T[i - 1].second, T[i - 1].third) + C[i].first,
min(T[i - 1].first, T[i - 1].third) + C[i].second,
min(T[i - 1].first, T[i - 1].second) + C[i].third
)
}
return minOf(T[N - 1].first, T[N - 1].second, T[N - 1].third)
}
fun main() {
val N = readln().toInt()
val C = Array<Triple<Int, Int, Int>>(N) {
readln().split(' ').map { s: String ->
s.toInt()
}.toTriple()
}
println(solve(N, C))
}

View File

@@ -0,0 +1,24 @@
val Mem = Array<Int>(1001) { i ->
if (i == 1) {
1
} else if (i == 2) {
3
} else {
0
}
}
fun get(N: Int): Int {
if (Mem[N] != 0) {
return Mem[N]
} else {
Mem[N] = (get(N - 1) + 2 * get(N - 2)) % 10007
return Mem[N]
}
}
fun main() {
val N = readln().toInt()
println(get(N))
}

View File

@@ -0,0 +1,60 @@
import java.util.PriorityQueue
import java.util.Scanner
fun solve(
N: Int,
M: Int,
D: MutableList<Int>,
E: HashMap<Int, MutableList<Pair<Int, Int>>>,
start: Int,
end: Int
): Triple<Int, Int, List<Int>> {
val pq = PriorityQueue<Triple<Int, Int, List<Int>>> { a, b -> a.first.compareTo(b.first) } // min heap
pq.add(Triple(0, start, listOf(start)))
D[start] = 0
val ret: MutableList<Triple<Int, Int, List<Int>>> = mutableListOf()
while (pq.isNotEmpty()) {
val (cost, now, path) = pq.remove()
if (cost > D[now]) {
continue
}
if (now == end) {
return Triple(cost, path.size, path)
}
for ((v, w) in E[now]!!) {
val nd = cost + w
if (D[v] > nd) {
D[v] = nd
pq.add(Triple(nd, v, path + listOf(v)))
}
}
}
println(D.toString())
return ret.last()
}
fun main() = with(Scanner(System.`in`)) {
val N = nextLine().toInt()
val D = MutableList<Int>(N + 1, { Int.MAX_VALUE });
val M = nextLine().toInt()
val E: HashMap<Int, MutableList<Pair<Int, Int>>> = HashMap()
for (i in 0..N) {
E[i] = mutableListOf()
};
for (i in 0 until M) {
val v = nextLine().trim().split(' ').map(String::toInt)
E[v.first()]!!.add(v[1] to v[2])
}
val (start, end) = nextLine().trim().split(' ').map(String::toInt)
val result = solve(start, M, D, E, start, end)
println(result.first)
println(result.second)
println(result.third.joinToString(separator = " "))
}

View File

@@ -0,0 +1,33 @@
fun solve(N: Int, S: Int, I: List<Int>): Int {
val D = ArrayDeque<Pair<Int, Int>>()
D.addLast(Pair(0, 0))
var cnt = 0
while (D.isNotEmpty()) {
val (now, accum) = D.removeLast()
if (now == N) {
if (accum == S) {
cnt += 1
}
continue
} else {
D.addLast(Pair(now + 1, accum)) // 안 더하기
D.addLast(Pair(now + 1, accum + I[now]))
}
}
if (S == 0) {
cnt -= 1;
}
return cnt
}
fun main() {
val (N, S) = readln().split(' ').map(String::toInt)
val I = readln().split(' ').map(String::toInt)
println(solve(N, S, I))
}

View File

@@ -0,0 +1,24 @@
fun bfs(N: Int): Int {
val D = ArrayDeque<Pair<Int, Int>>()
D.addLast(Pair(N, 0))
while (D.isNotEmpty()) {
val (now, step) = D.removeFirst()
if (now == 1) {
return step
}
if (now % 3 == 0) {
D.addLast(Pair(now / 3, step + 1))
}
if (now % 2 == 0) {
D.addLast(Pair(now / 2, step + 1))
}
D.addLast(Pair(now - 1, step + 1))
}
return -1
}
fun main() {
val N = readln().toInt()
println(bfs(N));
}

View File

@@ -0,0 +1,24 @@
fun solve(N: Int, A: Array<Int>): Int {
val T = Array<Triple<Int, Int, Int>>(N) {
Triple(0, 0, 0)
} // 0 안 마시기 ,1번째 마시기, 2번째 마시기
T[0] = Triple(0, A[0], 0)
for (i in 1 until N) {
T[i] = Triple(
maxOf(T[i - 1].first, T[i - 1].second, T[i - 1].third), T[i - 1].first + A[i], T[i - 1].second + A[i]
)
}
return maxOf(T[N - 1].first, T[N - 1].second, T[N - 1].third)
}
fun main() {
val N = readln().toInt()
val A = Array<Int>(N) {
readln().toInt()
}
println(solve(N, A))
}

View File

@@ -0,0 +1,5 @@
fun main() {
val n: Int = readLine()!!.toInt()
println("1")
println("0")
}

View File

@@ -0,0 +1,3 @@
fun main() {
print("Hello World!")
}

View File

@@ -0,0 +1,40 @@
import kotlin.math.*
class NarockSolver(val s: String) {
companion object {
val HAXIM: Int = 1000000007
}
fun solve(): Int {
var cntR = 0
var cntO = 0
var cntC = 0
var cntS = 0
var rfront = 1
for (v: Char in s) {
if (v == 'R') {
cntR += rfront
cntR %= HAXIM
} else if (v == 'O') {
cntO += cntR
cntO %= HAXIM
} else if (v == 'C') {
cntC += cntO
cntC %= HAXIM
} else if (v == 'K') {
cntS += cntC
cntS %= HAXIM
}
rfront *= 2
rfront %= HAXIM
}
return cntS
}
}
fun main() {
readLine()
val s: String = readLine()!!
val solver = NarockSolver(s)
println(solver.solve())
}

View File

@@ -0,0 +1,7 @@
fun main(){
val (a, b) = readLine()!!.split(" ")
val a_ = a.reversed().toInt()
val b_ = b.reversed().toInt()
if (a_ > b_) {println(a_)} else {println(b_)}
}

View File

@@ -0,0 +1,56 @@
import java.io.*
class GoldenTicketSolver(
val n: Int,
val m: Int,
val k: Int,
val teams: List<Pair<String, String>>
) {
fun solve(): List<String> {
val goldenticked = mutableListOf<String>()
val inst_goldenticked = mutableMapOf<String, Int>()
var kcnt = 0
for ((index, teaminst) in this.teams.withIndex()) {
if (index < this.m) {
inst_goldenticked[teaminst.second] = 1
} else {
if (kcnt >= this.k) {
break
}
val tmp = inst_goldenticked.getOrDefault(teaminst.second, 0)
if (tmp == 0) {
inst_goldenticked[teaminst.second] = 2
goldenticked.add(teaminst.first)
kcnt += 1
} else if (tmp == 1) {
continue
} else if (tmp == 2) {
continue
}
}
}
return goldenticked
}
}
fun main() {
val tknz = StreamTokenizer(System.`in`.bufferedReader())
fun StreamTokenizer.nextInt(): Int {
nextToken()
return nval.toInt()
}
fun StreamTokenizer.nextString(): String {
nextToken()
return sval
}
val (n, m, k) = (1..3).map { tknz.nextInt() }
val tms = (1..n).map { Pair(tknz.nextString(), tknz.nextString()) }
val solver = GoldenTicketSolver(n, m, k, tms)
val solved = solver.solve()
println(solved.size)
solved.forEach { i -> println(i) }
}