TopCoder problem "StringDecryption" used in SRM 480 (Division I Level Three)

Problem Statement

    TopCoder Security Agency (TSA) has successfully obtained the string encryption scheme used by the enemy to encrypt strings of digits. This encryption scheme can be described as follows:

Each non-empty maximum set of identical consecutive digits in the original string is replaced by an integer followed by a digit. The integer is the number of consecutive digits that are going to be replaced (without leading zeroes) while the digit is the same digit as those which are going to be replaced. For example, "122" will be replaced by "1122".

The procedure above is applied twice, first to the original string, and then to the result of the first application. For example, "122" becomes "1122" after one application, and becomes "2122" after the next application.

Although encryption is easily implemented with this procedure, retrieving the original data is not since there may be multiple original strings encrypted into the same resulting string. For example, "2122" may be the result of the encryption of the following strings: "122", a string consisting of 112 copies of digit '2' and a string consisting of 22222....22222 (211 '2's) copies of digit '2'.

It is conjectured that the enemy transmits some additional data that allows the encrypted string to be uniquely decrypted. However, TSA has no access to this data, so their only chance to decrypt the messages is to check all possible decryptions.

You are given a String[] code. Concatenate all elements of code in the order in which they are given to obtain a single string S. Compute the number of different strings that will be encrypted to S according to the scheme described above. Return this number modulo 1,000,000,009. If there are no such strings, return 0.


Method signature:int decrypt(String[] code)
(be sure your method is public)


-code will contain between 1 and 10 elements, inclusive.
-Each element of code will contain between 1 and 50 characters, inclusive.
-Each character in code will be a digit ('0'-'9').


Returns: 3
The example from the problem statement.
Returns: 0
Returns: 1555366
Returns: 0
Returns: 1
Returns: 882582353
Returns: 371459312
Returns: 95

Problem url:

Problem stats url:




PabloGilberto , ivan_metelsky ,

Problem categories:

Dynamic Programming, Encryption/Compression