Little Shikamaru And Caesar Cipher
Practice
4 (10 votes)
Approved
Medium Hard
Problem
92% Success 1256 Attempts 50 Points 2s Time Limit 256MB Memory 1024 KB Max Code

Yesterday's number theory class was taught by Shiho a member of the Konoha Cryptanalysis Team. She taught the young ninjas Caesar Cipher Encryption and how it is used in real missions. Little Shikamaru found the method very genius and beautiful.

enter image description here

So, when he came home, he came up with the following problem. Given two strings of digits initial and target, he will take any substring of length K or smaller from the initial string, and apply a right shift of any length he wants. He will repeat this process until he fully converts it to the target string, or he will stop if he thinks it is impossible. Little Shikamaru would like to know the minimum number of moves required to complete the conversion.

Note About Right Shifts:

Shifting right by x, means substituting every digit by the \(x^{th}\) digit after it, wrapping arround if needed. For example, when we shift "9" by 1, it will become "0".

Input Format:

Each test case starts with K the length of the substring. Second and third lines contain the initial and target strings, respectively.

Output Format:

Print the minimum number of moves in order to convert initial to target, else print 1 if it is impossible.

Constraints:

  • \(0 \le K \le 6\)
  • Length of initial and target are less than or equal \(50\)
  • Length of initial and target is the same

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:20
1 votes
Tags:
RecruitApprovedReadyEasyGrammar-VerifiedMathematicsMatrix Exponentiation
Points:50
22 votes
Tags:
Medium-Hard
Points:30
12 votes
Tags:
Dynamic ProgrammingCombinatoricsEasy-MediumReadyMathematicsOpenApproved