QCC P4 - Genetic Sequencing

View as PDF

Submit solution

Points: 5 (partial)
Time limit: 2.0s
Memory limit: 256M

Authors:
Problem type

Your next assignment from CodeVax is to help develop a COVID-19 vaccine. To do this, you must decode COVID-19's genetic sequence. More specifically, COVID-19's gene sequence is represented by an N by N grid of numbers. To decode COVID-19's genome sequence you must rotate given subgrids in a very specific way. Thankfully, other scientists have already figured out the sequence of rotating subgrids and given you Q instructions on what to do. You must apply these instructions in the order they were given to the given subgrid to complete the vaccine.

Let (r_1, c_1) and (r_2, c_2) represent the top left and bottom right corner of a square subgrid, respectively. Instructions will come in the form:

r1 c1 r2 c2 x: Rotate the square subgrid consisting of the points (r_1, c_1) and (r_2, c_2) clockwise by x degrees.

Given the N by N grid of numbers and Q such instructions, please print out COVID-19's decoded genetic sequence.

Input Specification

The first line of input will contain a positive integer, N.

The next N lines will each contain N positive integers.

The next line will contain a positive integer, Q.

The next Q lines will each contain the instructions on how to decode COVID-19's gene sequence.

Output Specification

Output COVID-19's genetic sequence after it has been decoded.

Constraints

For all subtasks:

2 \le N \le 100

1 \le Q \le 2 \times 10^3

1 \le r_1 < r_2 \le N

1 \le c_1 < c_2 \le N

-360 \le x \le 360

Every number in the grid will be a value in the range [1, 10^4].

It is guaranteed that x is a multiple of 90 and that r_2-r_1 = c_2-c_1.

Note that you will NOT be required to pass all the samples to receive points.

Subtask 1 [15%]

N = 2

Subtask 2 [85%]

2 \le N \le 100

Sample Input 1

2
1 2
3 4
1
1 1 2 2 90

Sample Output 1

3 1
4 2

Sample Input 2

4
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
5
1 1 4 4 360
2 2 3 3 -270
1 1 3 3 -90
2 2 4 4 180
3 2 4 3 90

Sample Output 2

3 6 7 4
2 16 15 14
1 8 12 5
13 11 9 10

Comments

There are no comments at the moment.