encryptedcounting
시간 제한1초메모리 제한2048 MB
시드 S에서 시작해 문자열이 C와 같아질 때까지 look-and-say 변환을 반복하고, 몇 번 반복했는지 출력한다.
문제
You and your friends have devised a clever method of encrypting numbers and have been using the method to talk to each other for the past few days. Unfortunately, your decryption tool broke so you need to create a new one.
The encryption is based on a sequence, where the next element of the sequence is derived by the "spoken" representation of the previous element. The encrypted version of a number, , is derived by finding the member of the sequence starting from some initial seed, . To decrypt a ciphertext, , one needs to find how many iterations it took to reach that from the given seed, .
Here is an example of how the sequence is generated:
// Comments describe how the number on the left
// was generated from the previous number.
0. 12 // "12" is our seed
1. 1112 // "12" is "one one" and "one two" -> 11, 12 -> 1112
2. 3112 // "1112" is "three ones" and "one two" -> 31, 12 -> 3112
3. 132112 // "3112" is "one three" and "two ones" and "one two" -> 132112
4. 1113122112
5. 311311222112
Your friend sends you a single line containing the seed, , and the ciphertext, . Output the decrypted number, , which describes the number of iterations your encryption algorithm takes to reach when starting at .
입력
Two integers, and , that are separated by a space. has less than digits, and has less than digits. Suppose the input is:
12 132112
where and . You then need to calculate, , which would be in this case (since the third iteration of the seed produces ).
출력
Output a single integer, , that is the number of iterations it takes to reach from the seed . The output for the above example would look like:
3