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 2 \times 2. 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.

Time complexity: \mathcal O(n)


Comments


  • 26
    andrewfeng123  commented on March 17, 2019, 8: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.


    • -6
      jasonwu10  commented on May 8, 2022, 4:13 p.m. edited

      This comment is hidden due to too much negative feedback. Show it anyway.


      • 1
        Plasmatic  commented on March 24, 2023, 4:02 p.m. edit 2

        It's still \mathcal O(n) because you need to read the full input.