Editorial for COCI '16 Contest 7 #3 Igra
Submitting an official solution before solving the problem yourself is a bannable offence.
We will construct a word letter by letter, starting from the first one, in a way that we try to place the lexicographically smallest letter to the current position. After we choose a letter, we need to check whether the remaining letters can be placed so that none of them match the same letter in Mirko's word (MR). Therefore, we are not interested in the order of these letters, but only if they can be arranged somehow.
Let a
, b
and c
, respectively, and a
, b
and c
in MR.
- Let's try to place
lettersa
to the positions of lettersb
in MR, i.e., reduce and by . - The remaining letters
a
we place to the positions of lettersc
in MR, i.e., reduce by and set to . - We set the remaining letters
b
in MR to lettersc
, i.e., reduce by and set to . - Now, we need to place the remaining letters
c
to the positions of lettersa
in MR, i.e., reduce by and set to .
If we couldn't have made any of the previous moves, that means no solution exists for the chosen b
can be placed to the positions of letters a
and c
in MR. This will hold if
We will test this out for each
Comments