Editorial for CCC '19 S1 - Flipper

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: KevinLu

Create a 2D array of size 2x2. Let: A[0][0] = 1, A[0][1] = 2, A[1][0] = 3, and A[1][1] = 4 as stated in the problem.

To reflect horizontally, swap A[0][0] with A[1][0] and swap A[0][1] with A[1][1].

To reflect vertically, swap A[0][0] with A[0][1] and swap A[1][0] with A[1][1].

For each character in the line of input, perform a horizontal reflection if the character is H and perform a vertical reflection if the character is V. This solution passes both subtasks.

Then output the 2D array as specified.

The time complexity for the solution is \mathcal O(n).


  • 18
    andrewfeng123  commented on March 17, 2019, 4:07 p.m.

    But the operations are commutative so you can just count the number of flips and mod 2. At most you'll need to do 1 V and 1 H.