DMPG '19 S2 - Code Cracking Crisis

View as PDF

Submit solution


Points: 7
Time limit: 1.0s
Memory limit: 64M

Author:
Problem type
Allowed languages
Ada, Assembly, Awk, Brain****, C, C#, C++, COBOL, CommonLisp, D, Dart, F#, Forth, Fortran, Go, Groovy, Haskell, Intercal, Java, JS, Kotlin, Lisp, Lua, Nim, ObjC, OCaml, Octave, Pascal, Perl, PHP, Pike, Prolog, Python, Racket, Ruby, Rust, Scala, Scheme, Sed, Swift, TCL, Text, Turing, VB, Zig

The evil Dr. Nope has planted a time bomb in the middle of the city, set to explode in exactly three hours!

Fortunately, Agent Double-O-Zero has gotten his hands on the bomb's deactivation code. Unfortunately, it's encrypted. Fortunately, Double-O-Zero has also gotten his hands on Dr. Nope's diary, which explains his encryption method in great detail!

The deactivation code is a string consisting of 1 \le N \le 1\ 000\ 000 digits from 0 to 9. Inside Dr. Nope's diary is a list of 10 strings numbered 0 to 9, the encryption keys. Each key is a permutation of the digits from 0 to 9.

To encrypt the deactivation code, the digits of the code are numbered from 0 to N - 1 from left to right. Let d[i] be the i-th digit of the unencrypted code and e[i] be the i-th digit of the encrypted code. Dr. Nope sets e[0] to be equal to d[0], and for every 1 \le i \le N - 1 after that, he sets e[i] to be the digit at the d[i]-th position of the d[i - 1]-th encryption key.

Can you help Double-O-Zero decrypt the code before it's too late?

Input Specification

The first 10 lines each contain one permutation of the 10 digits, the 10 encryption keys.
The final line contains one string of N digits, the encrypted deactivation code.

Output Specification

One string of N digits, the decrypted deactivation code.

Sample Input

1234567890
2345678901
3456789012
4567890123
5678901234
6789012345
7890123456
8901234567
9012345678
0123456789
4780

Sample Output

4254

Explanation for Sample

To encrypt 4254, the 4 stays the same. The 2 becomes the digit at the 2nd position of the 4th key, 7. The 5 becomes the digit at the 5th position of the 2nd key, 8. Finally, the 4 becomes the digit at the 4th position of the 5th key, 0. 4254 is the only value that becomes 4780 when encrypted.


Comments

There are no comments at the moment.