This page is still under construction.

Parts of this page are still being built. What you see may change.

Smoke Signals

Time limit1sMemory limit1024 MB

Summary
Parse a 26-letter Morse table and four pause lengths, then decode a binary smoke-signal string into text.
Level

Medium6 of 10

Topics
String, Implementation, Simulation, Hash map
Solved
No attempts yet

Problem

Figure 1: The Morse alphabet

Your friend is on a polar expedition, and to keep in touch she sends smoke signals encoded in Morse. You find it tedious to memorize the Morse alphabet, so you want to write a program that translates the signal for you. The input is a string of ones and zeros, where a run of ones corresponds to one smoke puff. Smoke puffs correspond to dashes and dots, and empty stretches correspond to pauses between dashes and dots, between letters, and between spaces.

Input

The first 2626 lines contain a table of the Morse code for every letter. Each such line contains one uppercase letter (A-Z), one space, and then the Morse encoding of that letter.

After the table comes a line with two distinct integers: SS and PP. SS is the number of ones that make up a dash, and PP is the number of ones that make up a dot.

Then comes a line with three distinct integers: TT, BB, and MM. TT zeros make up a pause between a dot and a dash, BB zeros signal a new letter, and MM zeros are one space.

Finally comes a line containing the number NN, followed by a string of NN ones and zeros.

Output

Your program must print one line containing the decoded message.

Constraints

  • 1≤S,P,T,B,M≤10001 \le S, P, T, B, M \le 1000
  • 1≤N≤300 0001 \le N \le 300\,000

Examples2

  1. Example 1

    Input
    A .-
    B -...
    C -.-.
    D -..
    E .
    F ..-.
    G --.
    H ....
    I ..
    J .---
    K -.-
    L .-..
    M --
    N -.
    O ---
    P .--.
    Q --.-
    R .-.
    S ...
    T -
    U ..-
    V ...-
    W .--
    X -..-
    Y -.--
    Z --..
    3 1
    1 2 3
    25 1010101001001011101110111
    
    Expected output
    HEJ
    
  2. Example 2

    Input
    A .-
    B -...
    C -.-.
    D -..
    E .
    F ..-.
    G --.
    H ....
    I ..
    J .---
    K -.-
    L .-..
    M --
    N -.
    O ---
    P .--.
    Q --.-
    R .-.
    S ...
    T -
    U ..-
    V ...-
    W .--
    X -..-
    Y -.--
    Z --..
    3 5
    5 3 4
    846 111110000011111000111000001110000111000111110000011100000111110001111100000111000111110000011100000111000001111100011111000001110000011100000111110001111100011100000111110000011111000011111000001111100011100000111110000111110000011100001111100000111110000011111000001110001111100011111000001110000011111000111000001111100000111000001110000111000001111100000111000001111100011100000111000001110001110000011100000111110000011111000111000001111100000111000001110000111000001111100000111000001111100011111000001110001110000011111000001111100000111110001111100000111110001110000011111000011100000111110000011111000111000001110000011100011100000111110001110000111110000011111000001111100011111000111000001111100011100000111110000011111000011111000001111100000111110000011111000111110001111100000111000001111100000111110001111100000111000001110000011111
    
    Expected output
    IM TRAPPED IN A VERY COZY CABIN DONT SEND HELP