-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsolution.kt
65 lines (60 loc) · 1.58 KB
/
solution.kt
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
fun main(args: Array<out String>) {
class FlyingSpaghettiMonster(val k: Int, val l: Int) {
var time = 0
var counter = 0
var isUsingMode = false
var isCompleted: Boolean
get() = !isUsingMode
set(value) {
isUsingMode = !value
}
val flushes = mutableListOf<Int>()
fun manFound() {
time += 1
if (isCompleted) {
counter += 1
if (counter >= k) {
isUsingMode = true
counter = 0
}
} else {
counter = 0
}
}
fun manNotFound() {
time += 1
if (isUsingMode) {
counter += 1
if (counter >= l) {
isUsingMode = false
flushes.add(time)
counter = 0
}
} else {
counter = 0
}
}
fun complete() {
if (isUsingMode) {
time += l - counter
flushes.add(time)
}
}
}
val (k, l) = readLine()!!.split(" ").map { it.toInt() }
val men = readLine()!!.toCharArray().map { it == '1' }
val fsm = FlyingSpaghettiMonster(k, l)
for (man in men) {
if (man) {
fsm.manFound()
} else {
fsm.manNotFound()
}
}
fsm.complete()
fsm.flushes
.map { it.toString() }
.ifEmpty { listOf("NIKAD") }
.joinToString("\n")
.let(::println)
}