|시간 제한||메모리 제한||제출||정답||맞힌 사람||정답 비율|
|1 초||128 MB||5||2||2||40.000%|
Assume you have a set of cards laid out in an n by m grid. The cards are numbered and some are face up and others are face down. We can collapse the grid into a single pile by using a series of flips, each of which is one of the four following types:
After a series of n + m − 2 flips, the cards will be in a single pile, some cards face up and some face down. Your job is to determine the order of the face up cards in this final pile.
Each test case will start with a line containing two positive integers n m indicating the number of rows and columns in the grid. After this will come n rows of m integers indicating each card’s number and its orientation. (The first row is the top row and the first value in each row is the leftmost card.) If a value is a positive integer k that means card k is at the location face up; if a value is a negative integer -k that means card k is at the location face down. (k will never be zero.) After these n rows there will be one more line containing n + m − 2 characters indicating the order of flips to apply to the grid. Each character will be either T, B, L or R corresponding to a top, bottom, left or right flip. All flip sequences will be legal, i.e., you won’t be asked to do more than n − 1 top and bottom flips or m − 1 left and right flips. The maximum value for n and m is 20. A line containing two zeros will terminate input.
For each test case, output the case number followed by a list of the numbers of all of the face up cards in the final deck, starting from the bottom of the deck. Follow the format used in the examples.
2 3 4 -17 -8 6 23 -5 LRB 1 1 -3 1 1 3 0 0
Case 1: 8 6 Case 2: Case 3: 3