Editorial for CCC '24 S1 - Hat Circle


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.

Subtask 1

We note that there can only be either 2 or 4 people at the table. This can be solved with conditional statements. In the case that there are only 2 people, they are seated across from each other, so we just compare the values of both hats. With 4 people, we can compare the equality of the hats at seat 1 and 3 and seat 2 and 4.

Subtask 2

All people have the same hat number 1. This means we can simply count the number of people at the table.

Subtask 3

Since people in even-numbered seats have hat number 1 and people in odd-numbered seats have hat number 0, they will only see matching hats is if the number of people is divisible by 4.

Subtask 4

There was no specific intended approach for this subtask. We observe that in a circular arrangement, the person in seat i is directly opposite to the person in seat i + \frac{N}{2}.

One possible solution would be to store for each hat number, a list of the seat numbers of the people wearing that hat number. We can then iterate over the lists for each hat number and check if for each seat i in a list, if both i and i + \frac{N}{2} exist in the same list.

Subtask 5

We notice that we can do the check directly on the input as a list. For each person at seat i, we check if the opposite person at seat i + \frac{N}{2} has the same hat number. Since each seat is indexed from 1 to N, if i > \frac{N}{2} then i + \frac{N}{2} will be greater than N. To ensure that we stay within bounds, there are a couple approaches we can use:

  • loop from 1 to N and compare i and (i + \frac{N}{2}) \% N to count person at seat i;
  • loop from 1 to N and subtract N from i + \frac{N}{2} if it is greater than N to count person at seat i;
  • loop from 1 to N and count for person at seat i and seat i + \frac{N}{2}.

Comments

There are no comments at the moment.