DCP-510: The Secret Scroll Back to All Problems

Medium String > Basic


A **combination lock** is a type of locking device in which a sequence of symbols, usually numbers, alphabets, is used to open the lock. A **four** digit combination lock is a device that contains **four** wheels with **26** slots in each. Each slot contains a single character from (**A – Z** ) .You can rotate each of the wheel independently ,towards upward and downward, and can make any words that contains only of **four** alphabets. A **notation pointer** denoted the starting position i.e. the starting alphabet combination from which the rotation should start. ![Combination Scroll][1] **Genjamin Bates** is a famous treasure hunter. The last clue to solve the mystery now depends on unlocking the scroll as fast as possible. To unlock the device faster he asked you to design a system that will calculate the minimum seconds to unlock the scroll. A rotation to the next state takes **1** second. Input: ------ Input starts with an integer which denotes the number of test cases you need to perform **TC**.<br> Each test case contains **4** lines where each line contains 26 alphabets which will be uppercase English alphabet.<br> The first line ( **A<sub>1</sub>, A<sub>2</sub>, A<sub>3</sub>, … , A<sub>26</sub>**) denotes the alphabet of the first wheel. Similarly, for the second (**B<sub>1</sub>, B<sub>2</sub>, B<sub>3</sub>, … , B<sub>26</sub>**), third ( **C<sub>1</sub>, C<sub>2</sub>, C<sub>3</sub>, … , C<sub>26</sub>**) and fourth wheel ( **D<sub>1</sub>, D<sub>2</sub>, D<sub>3</sub>, … , D<sub>26</sub>**). <br> As all of them are wheel, it is pretty clear that the last alphabets of each list connected to the first alphabet of that list. <br> Now you have to perform **Q** queries. Each query contains two strings ( **S** and **T** ). The first one denotes the string where the **notation pointer** is pointing at for all of the four wheels. The second one denotes the secret combination lock. Constraints ------ 1 <= **TC** <= 15<br> ‘A’ <= ( **A<sub>1</sub>, A<sub>2</sub>, A<sub>3</sub>, … , A<sub>26</sub>**) <= ‘Z’<br> ‘A’ <= (**B<sub>1</sub>, B<sub>2</sub>, B<sub>3</sub>, … , B<sub>26</sub>**) <= ‘Z’<br> ‘A’ <= ( **C<sub>1</sub>, C<sub>2</sub>, C<sub>3</sub>, … , C<sub>26</sub>**) <= ‘Z’<br> ‘A’ <= ( **D<sub>1</sub>, D<sub>2</sub>, D<sub>3</sub>, … , D<sub>26</sub>**) <= ‘Z’<br> 1 <= **Q** <= 10<sup>5</sup><br> **|S| , |T|** = 4 Output: ------- For each test case, you need to print the number of the test case as “**Case X**”, where **X** denotes case number.<br> Next **Q** lines contain the result of queries where you need to find minimum number of seconds to bring alphabets of combination **T** at the notation pointer from the combination S. That means after some (may be 0) movement of wheels the notation pointer will point the string **T**. Have a look to the samples for better understandings. **Please use fast I/O methods.** Sample Input ------------ 1 ABCDEFGHIJKLMNOPQRSTUVWXYZ BCDEFGHIJKLMNOPQRSTUVWXYZA CDEFGHIJKLMNOPQRSTUVWXYZAB DEFGHIJKLMNOPQRSTUVWXYZABC 1 CEGI DFHJ Sample Output ------------- Case 1: 4 [1]: https://s3-ap-southeast-1.amazonaws.com/devskillimagestorage/questionimages/3e20f539-f9f4-c378-6867-08d584e60a4f_c8c7a4dfd35c4dbcb4c1315d57bf564b_W702xH242.png


Problem Setter:

Avik Sarkar

Please login to submit solution to this problem.

Problem Limits

Language Time Limit (seconds)
C 0.50
C++ 0.50
C++14 0.50
C# 1.00
Go 1.00
Java 1.00
JavaScript 1.00
Objective-C 1.00
Perl 1.00
PHP 1.00
Python 1.00
Python3 1.00
Ruby 1.00
VB.Net 1.00

Problem Stats

38/181

Solve/Submission

Ranking

# User Language Timing
01 durlov1234 Cpp 0.20s
02 CLown1331 Cpp14 0.21s
03 Ramprosad Cpp14 0.21s
04 muradhossen Cpp 0.23s
05 sayedgkm Cpp14 0.23s
06 obaydullahmhs Cpp 0.23s
07 mir003 Cpp 0.23s
08 prodipdatta7 Cpp14 0.24s
09 _c_k_r_ Cpp 0.24s
10 _dipu Cpp14 0.24s
11 Islam_Rafat Cpp 0.24s
12 mobasshir Cpp14 0.25s
13 feodorv C 0.26s
14 a_rahman Cpp 0.26s
15 njrafi Cpp 0.28s
16 inam Cpp14 0.28s
17 fayedanik Cpp 0.29s
18 emrul Cpp 0.29s
19 badassiumoxide Cpp 0.29s
20 Fahim_41 Cpp14 0.30s
21 Limon_88 Cpp14 0.30s
22 SakibAlamin Cpp14 0.30s
23 anik_JU Cpp 0.30s
24 Fahim_ju Cpp 0.30s
25 alif_cse_ju Cpp14 0.31s
26 mahadi97 Cpp 0.31s
27 Riad_IIT7 Cpp14 0.32s
28 Frdhsn Cpp14 0.33s
29 subhashis_cse Cpp 0.33s
30 shamimjucse Cpp14 0.33s
31 AlaminJust Cpp 0.34s
32 notorious_94 Cpp 0.37s
33 rezaulhsagar Cpp 0.39s
34 SAIF_IIT8_JU Cpp 0.40s
35 yead_025 Cpp 0.41s
36 Bruteforcekid Cpp14 0.47s
37 mh755628 Cpp14 0.48s
38 duronto20 Cpp 0.49s
Feedback

Your feedback is our precious!



Or call +88 02 9853138 for support