No.509 Fill Tool
Problem Statement
Hamuko used the drawing software Paint to create an image with black digits on a white background.
However, she realized that what she actually needed was an image with white digits on a black background.
Since remaking the image from scratch would be troublesome, Hamuko is trying to do this using only the "fill tool".
The fill tool changes everything to the specified color as long as adjacent colors are the same.
What is the minimum number of times the fill tool must be used to change the image?
The colors usable in one image change are limited to "white", "black", and "one color other than white and black".
Input
n
$0 \leq n \leq 10^9$, $n$ is an integer.
The shape of each digit is as follows.
Output
Output the minimum number of times described above on one line. Print a newline at the end.
Sample
Sample 1
Input
6
Output
4
The original image looks as follows.
(1) Fill the character 6 itself with red.
(2) Fill the background with black.
(3) Fill the hole of the 6 with black.
(4) Fill the character 6 itself with white.
Sample 2
Input
1
Output
3
The original image looks as follows.
(1) Fill the character 1 itself with blue.
(2) Fill the background with black.
(3) Fill the character 1 itself with white.
Sample 3
Input
1046928
Output
21
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。
はむこ
ixmel