Editorial for LCC '23 Contest 1 J4 - Candy Plan


Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.

Submitting an official solution before solving the problem yourself is a bannable offence.

Author: AngelsandDevsLOL

This problem wants you to rotate an N by N grid by K degrees clockwise and print it. Knowing that K is a multiple of 90, we simply need to rotate the array by 90 degrees clockwise K / 90 times. If we want to rotate the array by 270, we rotate it by 90 degrees 3 times. Notice that when an array is rotated, every element will also be moved.

Let (x, y) be an element in array[x][y]. The following directions assume that the array is 0-indexed:

When K = 0, there is no rotation.

When K = 90, or when the array is rotated once, every element (x, y) will go to (y, N - x - 1).

When K = 180, every element (x, y) will go to (N - x - 1, N - y - 1).

When K = 270, every element (x, y) will go to (N - y - 1, x).


Comments

There are no comments at the moment.