Editorial for CCC '24 S2 - Heavy-Light Composition


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

Subtask 1

Hard-code every possible string containing "a" and "b" of length between 2 and 4 (there are 30 such strings) and output whether it alternates between heavy "a" and light "b" or heavy "b" and light "a".

Subtask 2

There was no intended solution for this subtask. It was intended to allow for possibly slower full solutions.

Subtask 3

We consider two cases for if it starts with "a" or not:

  • Check that every second letter is "a" and that the rest are not "a".
  • Check that every second letter is not "a" and that the rest are "a".

If either case is true, output T; otherwise, output F.

Subtask 4

First, create an array that will store the frequency of each letter in the string. Each element represents the count of a particular letter. Then, iterate over all letters in the string and increment the frequency of it in the array.

We realize we can extend the logic from subtask 3 with this array. If a letter has a frequency greater than 1 in the array, it is heavy; if not, it is light.

We consider two cases for if it starts with a heavy letter or not:

  • Check that every second letter has a frequency greater than 1 and that the rest are light.
  • Check that every second letter does not have a frequency greater than 1 and that the rest are heavy.

If either case is true, output T; otherwise, output F.


Comments

There are no comments at the moment.