## Editorial for DMOPC '22 Contest 5 P6 - Threes and Twos

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: 4fecta

#### Method 1

We will solve this problem by hand. After a bit of initial experimentation, we may find that

.#.
###

is a non-trivial region without a winning tiling. Why not? The diagram below helps to illustrate the issue:

.A.
#A#

Any winning tiling must contain a tile covering the two As, but then at most one of the #s can be covered, making a winning tiling impossible! Unfortunately, it is not a frustrating region because it does not satisfy the third property. However, we can still capitalize on the lesson learned from this example: we want to create patterns with more lone #s than there are A "gadgets". To circumvent the issue of violating property three, we can take advantage of the extra connectivity that cycles provide. For example, here is the first solution ever found to this problem by zhouzixiang2004 which uses 13 A gadgets and 14 lone #s:

.A...A.A.A
.A#A#A#A#A
.#.A.#...#
AA...AA.AA
.#.A.#...#
.A#A#A#A#A
.A...A.A.A

Another pretty pattern was submitted by hitonanode which uses 9 A gadgets and 10 lone #s:

.A.A...
.A#A#AA
.#.#.#.
AAAA.AA
.#.#.#.
AA#A#A.
...A.A.

Just for illustrative purposes, we may observe another pattern submitted by siganai using 8 A gadgets and 9 lone #s:

.A.A.A.
.A#A#A.
.#.#.#.
AA#A#AA
.#.A...
AA#AA..

Finally, the most optimized solution using loops for assistance is as follows, with 6 A gadgets and 7 lone #s:

A.A.A
A#A#A
# # #
A#A#A
A.A.A

For full marks, we will need to think outside of the box and abandon the loops entirely. As it turns out, the following solution uses only 4 A gadgets and 5 lone #s, and is demonstrably the most efficient solution to the problem:

..A..
.#A#.
AA#AA
.#A#.
..A..

#### Method 2

We will solve this problem using the solution to the previous problem and a brute force search. If we know that the optimal solution fits into a box (perhaps after finding a solution that is almost optimal by hand), then we can enumerate all possible regions contained in this box and find the smallest one which satifies all four properties. Empirically, this takes around a couple of minutes before finding the optimal solution.

If we do not know the size of the bounding box, it is still possible to solve the problem in a systematic and efficient manner: by using a polyomino enumerator. Note that https://oeis.org/A000105 gives the number of distinct polyominoes with cells. We see that there are distinct polyominoes of size . Using an efficient polyomino generator, this approach should find the optimal solution almost instantly. Thanks to jeroenopdebeek for discovering this solution.