-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlib.kt
More file actions
49 lines (42 loc) · 1016 Bytes
/
lib.kt
File metadata and controls
49 lines (42 loc) · 1016 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import java.math.*
import kotlin.math.*
fun solve() {
}
fun main() {
var t = 1;
t = readInt()
while (t-- != 0) {
solve()
}
}
private fun readLn() = readLine()!!
private fun readInt() = readLn().toInt()
private fun readStrings() = readLn().split(" ")
private fun readInts() = readStrings().map { it.toInt() }
class yesno(y: String, n: String) {
private val yes = y
private val no = n
operator fun invoke(ok: Boolean): String { return if (ok) this.yes else this.no }
}
fun prefixFunction(s: String): Array<Int> {
val n = s.length
val p = Array(n) {0}
for (i in 1 until n) {
var j = p[i - 1]
while (j > 0 && s[j] != s[i])
j = p[j - 1]
if (s[i] == s[j])
j++
p[i] = j
}
return p
}
fun KnuthMorris(s: String, t: String): Int {
val p = prefixFunction("$s#$t")
val n = s.length
val m = t.length
for (i in n + 1 .. n + m)
if (p[i] == n)
return i - n - n
return -1
}