問題一覧 > 通常問題

No.509 Fill Tool

レベル : / AI推定難易度 : 800 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 260
作問者 : はむこ / テスター : ixmel
お気に入りにしたユーザー ProblemId : 1337 / 自分の提出
問題文最終更新日: 2026-06-28 17:06:45
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 162 (順位表) の他の問題:

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もしくは右上の雲マークをクリックしてアカウントを作成してください。