## Editorial for DMOPC '18 Contest 6 P2 - Enantiomers

**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.**

Authors:

First, notice that it is possible for the two molecules to be enantiomers only if, for each group used, the number of occurrences of in molecule 1 equals the number of occurrences of in molecule 2.

If the above holds and **two or more of the groups used are the same**, the two molecules will **always be identical**, and thus are not enantiomers (try it!).

Therefore, it is possible for the molecules to be enantiomers only if there is a **different group at each vertex**. If this property also holds, **and** the two molecules are **not identical**, it is **always possible** to rotate one to become the mirror image of the other, and thus they are enantiomers. To see why, order the groups alphabetically. If we rotate the molecules so that the first group is at vertex 1 and the second is at vertex 4, there are only 2 possibilities for the positions of the last two groups:

One of these configurations results in an identical molecule, while the other results in an enantiomer. (This means that it is actually not necessary to check reflections; if two of these molecules are not identical, they must be enantiomers!)

Therefore, it suffices to check that both of the molecules use **exactly the same groups**, then check that they are **not identical** by verifying that it is impossible to rotate one to match the other. There are only 12 different 3D rotations we need to check: 4 choices for the top vertex times 3 choices for the leftmost base vertex.

## Comments