Editorial for IOI '19 P5 - Vision Program
Submitting an official solution before solving the problem yourself is a bannable offence.
Let's call a right diagonal a set of pixels that have coordinates
In a similar manner, let's call a left diagonal a set of pixels that have coordinates
Lemma. Distance between two pixels
Proof. The condition on diagonals can be written as follows:
This is equivalent to:
This in turn is equivalent to the following four double inequalities:
Finally, this is equivalent to
The algorithm then is as follows:
- Add an instruction for each diagonal (both left and right ones) indicating whether there is a black pixel within the diagonal.
- Add an instruction for each diagonal (both left and right ones) indicating whether there are two black pixels within the diagonal (combining OR and XOR might come in handy).
- Using instructions from 1. and 2., for each block of
consecutive left diagonals have an instruction that reports whether there are two black pixels within the block. - Do the same for right diagonals.
- Add a gate that returns true if and only if there is at least one gate from 3. and at least one gate from 4. that both return true.
- Repeat steps 3. — 5. for
instead of . - The pixels are at distance
if and only if 5. reports true but 6. reports false.
The algorithm requires
Comments