Flip and Turn
Time limit2sMemory limit64 MB
Simulate up to 100000 sequential matrix transformations (transpose, flip, rotate) efficiently and output the final matrix.
- Level
Medium5 of 10
- Topics
- Matrix, Simulation, Implementation
- Solved
- No attempts yet
Problem
You are given a matrix of printable characters with rows and columns. Rows are numbered from by the first index and columns from by the second index. A single operation replaces the current matrix with a new matrix according to one of the following rules (the character in backticks is the operation identifier).
- Transpose over the main diagonal (
1): - Transpose over the anti-diagonal (
2): - Horizontal flip (
H): - Vertical flip (
V): - Clockwise rotation by (
A), (B), or (C) degrees; the -degree case is - Counterclockwise rotation by (
X), (Y), or (Z) degrees; the -degree case is
You are given a sequence of at most 100,000 operations from this set. Apply them to the matrix in the given order and output the resulting matrix.
Input
The first line contains two integers and (). Each of the next lines contains exactly printable characters, where a printable character is a symbol whose ASCII code is between and inclusive; these lines contain no other symbols. The following line contains the sequence of operations, each given by its one-character identifier, to be applied from left to right.
Output
Print two integers: the number of rows and the number of columns of the resulting matrix. Then print the resulting matrix in the same format as the input.