encryptedcounting

시간 제한1초메모리 제한2048 MB

요약
시드 S에서 시작해 문자열이 C와 같아질 때까지 look-and-say 변환을 반복하고, 몇 번 반복했는지 출력한다.
난이도

보통10점 중 5점

유형
문자열, 시뮬레이션, 구현, 완전 탐색
정답자
아직 제출이 없습니다

문제

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, MM, is derived by finding the MthM^{th} member of the sequence starting from some initial seed, SS. To decrypt a ciphertext, CC, one needs to find how many MM iterations it took to reach that CC from the given seed, SS.

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, SS, and the ciphertext, CC. Output the decrypted number, MM, which describes the number of iterations your encryption algorithm takes to reach CC when starting at SS.

입력

Two integers, SS and CC, that are separated by a space. SS has less than 1010 digits, and CC has less than 200200 digits. Suppose the input is:

12 132112

where S=12S = 12 and C=132112C = 132112. You then need to calculate, MM, which would be 33 in this case (since the third iteration of the seed produces 132112132112).

출력

Output a single integer, MM, that is the number of iterations it takes to reach CC from the seed SS. The output for the above example would look like:

3

예제2

  1. 예제 1

    입력
    12 132112
    
    예상 출력
    3
    
  2. 예제 2

    입력
    21 13211311123113112211
    
    예상 출력
    7