-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathbj_A-B.kt
More file actions
48 lines (38 loc) · 945 Bytes
/
bj_A-B.kt
File metadata and controls
48 lines (38 loc) · 945 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
fun calculation(q: ArrayDeque<Long>, cnt: Int, b: Int): Int {
if (q.filter { it == b.toLong() }.size == 1) {
return cnt+1
}
if (q.isEmpty()) {
return -2
}
val newQ = ArrayDeque<Long>()
for (j in q.indices) {
newQ.add(q[j])
}
q.clear()
for (i in newQ.indices) {
val mul = newQ[i] * 2
val add = (newQ[i].toString() + "1").toLong()
if (mul <= b.toLong()) {
q.add(mul)
}
if (add <= b.toLong()) {
q.add(add)
}
}
/*println("new" + newQ)
println(q)*/
val setCnt = cnt + 1
return calculation(q, setCnt, b)
}
fun main() {
val (a,b) = readln().split(" ").map { it.toInt() }
val cnt = 0
val mul = (a * 2).toLong()
val add = (a.toString() + "1").toLong()
val q = ArrayDeque<Long>()
q.add(mul)
q.add(add)
val answer = calculation(q,cnt,b) + 1
println(answer)
}