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
or
people at the table. This can be solved with conditional statements. In the case that there are only
people, they are seated across from each other, so we just compare the values of both hats. With
people, we can compare the equality of the hats at seat
and
and seat
and
.
Subtask 2
All people have the same hat number
. This means we can simply count the number of people at the table.
Subtask 3
Since people in even-numbered seats have hat number
and people in odd-numbered seats have hat number
, they will only see matching hats is if the number of people is divisible by
.
Subtask 4
There was no specific intended approach for this subtask. We observe that in a circular arrangement, the person in seat
is directly opposite to the person in seat
.
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
in a list, if both
and
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
, we check if the opposite person at seat
has the same hat number. Since each seat is indexed from
to
, if
then
will be greater than
. To ensure that we stay within bounds, there are a couple approaches we can use:
- loop from
to
and compare
and
to count person at seat
;
- loop from
to
and subtract
from
if it is greater than
to count person at seat
;
- loop from
to
and count for person at seat
and seat
.
Comments