WC '16 Contest 2 S3 - Turbolift Testing

View as PDF

Submit solution


Points: 15 (partial)
Time limit: 1.8s
Memory limit: 64M

Author:
Problem type
Woburn Challenge 2016-17 Round 2 - Senior Division

Lieutenant commander Scetty has been assigned quite the tedious task - testing a turbolift. Hardly a job worthy of the Enterprise's chief engineer! This particular turbolift has just 2 buttons - one to take the turbolift up 1 floor, and another to take it down 1 floor.

One "button press" is an action consisting of, well, pressing one of the buttons. It can be represented as a single character, either U if the up button is pressed, or D if the down button is pressed.

One "button sequence" is an ordered sequence of one or more button presses. The turbolift has the ability to perform N (1N200000) different types of button sequences, numbered from 1 to N, with the ith one represented by the string Bi. The jth character in this string represents the jth button press in the sequence. The strings B1N are not necessarily distinct, and the sum of their lengths is at most 200000.

The turbolift will start on floor 0 of the Enterprise. Due to recent technological advances, the ship has infinitely many floors above floor 0 (numbered upwards from 1), and infinitely many basement floors below it (numbered downwards from 1). As part of the testing process, it will then be programmed to execute M (1M200000) button sequences, one after another. The ith button sequence in this sequence of sequences will be button sequence is Si (1SiN). Note that some button sequences could be executed multiple times during the testing, while others could not be executed at all.

Throughout the process, Scetty will make notes about how low and high the turbolift ends up getting. In particular, he has Q (1Q200000) questions to answer. The ith one asks: "After the first Pi button presses, what are the minimum and maximum floor numbers that the turbolift will have reached up to that point?". Pi is a positive integer no greater than the total number of button presses which will be executed throughout the sequence of M button sequences. Note that both Pi and the answers may not fit within a 32-bit integer.

In test cases worth 12/27 of the points, N3000, M3000, and no single button sequence consists of more than 3000 button presses.

Input Specification

The first line of input consists of three space-separated integers N, M, and Q.
N lines follow, the ith of which consists of a single string Bi (for i=1N).
M lines follow, the ith of which consists of a single integer Si (for i=1M).
Q lines follow, the ith of which consists of a single integer Pi (for i=1Q).

Output Specification

Output Q lines, the ith of which should consist of two space-separated integers - the lowest and highest floors that the turbolift will reach after no more than Pi button presses (for i=1Q).

Sample Input

Copy
2 3 3
DDUU
U
2
1
2
1
6
4

Sample Output

Copy
0 1
-1 2
-1 1

Sample Explanation

The turbolift will receive 6 button presses in total, with the following results:

Copy
Button | Floor
-------+------
   U   |   1
   D   |   0
   D   |  -1
   U   |   0
   U   |   1
   U   |   2

Comments

There are no comments at the moment.