GUPTA MECHANICAL

IN THIS WEBSITE I CAN TELL ALL ABOUT TECH. TIPS AND TRICKS APP REVIEWS AND UNBOXINGS ALSO TECH. NEWS .............

Sunday 10 July 2022

[Solution] Touchbar Typing Round D 2022 | Kick Start 2022 Solution


Problem

Glide Typing task in Crowdsource app uses a new Google keyboard to type a word by sliding a finger across keys without lifting the finger, as shown in the animation below.

To make the Glide Typing task more challenging, instead of a normal keyboard, we have a special linear keyboard K that has all the keys in one row.

Imagine that you want to type a word S that is N characters long. The linear keyboard K has M keys. It is guaranteed that the keys cover all characters in S. However, some of the keys may be duplicates. In other words, for each character in S, there is one or more keys in K mapped to the character. Note that, all characters and keys are represented as integers.

You may start with your finger on any key. It takes 1 second to move your finger from a key to an adjacent key. Due to Glide Typing, there is no pressing a key. If the finger is currently at the key i which has character Ki, and we want to type the character Kj at index j, we will glide the finger from the key i to the key j, which takes |ji| seconds. If your finger is at key x, you can type character Kx any number of times instantly. You need to type string S character by character. Formally, you need to type Si before Si+1 for each 1iN1.

Solution Click Below:-  👉CLICK HERE👈
👇👇👇👇👇


For example, suppose the word S has characters: 12234. You can start by keeping your finger on key with character 1 on the keyboard which is at index i. Then you glide your finger to key which has character 2 which is at index j. It would take |ji| seconds. In order to type character 2 two times in string S, you can do that in no additional time as |jj|=0 seconds. Then you can continue to glide your finger to type the other characters in the word S sequentially.

Can you calculate the minimal time needed to type the word?

Input

The first line of the input gives the number of test cases, TT test cases follow.






The first line of each test case contains one integer N: the length of the word S.
The second line of each test case contains N integers: each Si is the character at the i-th index.
The third line of each test case contains one integer M: the length of the keyboard K.
The fourth line of each test case contains M integers: each Ki is the character at the i-th key.

Output

For each test case, output one line containing the minimal time needed to type the word. Case #xy, where x is the test case number (starting from 1) and y is the minimal time needed to type S on the keyboard K.

Limits

Memory limit: 1 GB.
1T100.
All characters in S appears at least once in K.
1Ki2500.
1Si2500.

Test Set 1

Time limit: 20 seconds.
1N100.
1M100.
It is guaranteed that there are no duplicated keys in keyboard K.

Test Set 2

Time limit: 20 seconds.
1N100.
1M100.

Test Set 3

Time limit: 40 seconds.
1N2500.
1M2500.

No comments:

Post a Comment