Editorial for Art Academy VII: A Mysterious Object
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.
Submitting an official solution before solving the problem yourself is a bannable offence.
Author:
For the subtask, looping from
to
and checking if the number contains
as a subsequence passes. Make sure the number doesn't contain
as a subsequence.
For the remaining , we use dynamic programming.
The dp state should be .
is between
and the number of digits in
. It represents which digit you are at in
.
is either
,
, or
. It represents zero previous occurrences of
, a previous occurrence of
, and a previous occurrence of a
and a
, respectively.
is either
or
. It represents if the number being considered is currently less than
.
The transition is left as an exercise to the reader.
Comments