Editorial for COCI '20 Contest 1 #1 Patkice
Submitting an official solution before solving the problem yourself is a bannable offence.
We save the input as a matrix . Let the starting island have coordinates
, so
o. We will try to send the ducks to each of the four directions, yielding four paths. For each of these paths, we count through how many cells it passes before reaching x, or say the distance is infinite if the path ends in . or o.
Implementation: we run the following algorithm four times, starting from ,
,
and
. We maintain the current duck position as
, and the length of the path in a variable
initialized to
. If
is in
<>^v, increment and move
in the corresponding direction. (We can use
dict or std::map, mapping the ordered pairs which describe the direction to characters, e.g. {'>': (0, 1)}). If equals
o or ., set and stop processing this path. We are done if
equals
x.
After the previous part, we have the distances ,
,
and
. If all
, there is no solution and we print
:(.
Else, we print :) and the letter for which
is minimal, breaking ties alphabetically.
Comments