Editorial for An Animal Contest 3 P2 - Monkey Potato
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:
Denote to be the set of all valid digits given in input.
Subtask 1
For this subtask, notice that we can take the smallest digit in and output it
times.
Time Complexity:
Subtask 2
Consider cases:
:
- No valid integer can be formed with the digit
, so
-1
should be outputted.
- No valid integer can be formed with the digit
:
Let the second smallest digit in
be
.
- The smallest palindrome consists of
's.
- The smallest palindrome consists of
- A
length palindrome can be constructed with the form:
.
- A
:
- Let the smallest digit in
be
. The
length palindrome is:
.
- Let the smallest digit in
Time Complexity:
Comments