Magicka™ is an action-adventure game developed by Arrowhead Game Studios. In Magicka you play a wizard, invoking and combining elements to create Magicks. This problem has a similar idea, but it does not assume that you have played Magicka.
Note: "invoke" means "call on." For this problem, it is a technical term and you don't need to know its normal English meaning.
As a wizard, you can invoke eight elements, which are the "base" elements. Each base element is a single character from
We will specify pairs of base elements that combine to form non-base elements (the other 18 capital letters). For example,
We will specify pairs of base elements that are opposed to each other. After you invoke an element, if it isn't immediately combined to form another element, and it is opposed to something in your element list, then your whole element list will be cleared.
For example, suppose
( and combine to form ) ( and can't combine because they were never at the end of the element list together) ( and are opposed, so the list is cleared; then is invoked) ( and are opposed, so the list is cleared) ( combine to make , so the list is not cleared) ( and are opposed, so the list is cleared)
Given a list of elements to invoke, what will be in the element list when you're done?
Input Specification
The first line of the input gives the number of test cases,
First an integer
Output Specification
For each test case, output one line containing Case #x: y
, where
Limits
Each pair of base elements may only appear together in one combination, though they may appear in a combination and also be opposed to each other.
No base element may be opposed to itself.
Unlike in the computer game Magicka, there is no limit to the length of the element list.
Memory limit: 1GB.
Small dataset
Time limit: 30 seconds.
Large dataset
Time limit: 60 seconds.
Sample Input
5
0 0 2 EA
1 QRI 0 4 RRQR
1 QFT 1 QF 7 FAQFDFQ
1 EEZ 1 QE 7 QEEEERA
0 1 QW 2 QW
Sample Output
Case #1: [E, A]
Case #2: [R, I, R]
Case #3: [F, D, T]
Case #4: [Z, E, R, A]
Case #5: []
Magicka™ is a trademark of Paradox Interactive AB. Paradox Interactive AB does not endorse and has no involvement with Google Code Jam
Note
This problem has different time limits for different batches. If you exceed the Time Limit for any batch, the judge will incorrectly display >60.000s
regardless of the actual time taken. Refer to the Limits section for batch-specific time limits.
Comments