6731.Removing Digits

Time Limit: 1s Memory Limit: 512MB

You are given an integer $n$ . On each step, you may subtract one of the digits from the number.

How many steps are required to make the number equal to $0$ ?

Input Format(From the terminal/stdin)

The only input line has an integer $n$ .

  • $1 \le n \le 10^6$

Output Format(To the terminal/stdout)

Print one integer: the minimum number of steps.

Sample Input

Copy
27
  \n

Sample Output

Copy
5
 \n

An optimal solution is $27 \rightarrow 20 \rightarrow 18 \rightarrow 10 \rightarrow 9 \rightarrow 0$ .

Source: CSES, Dynamic Programming, 1637

Submit

请先 登录

© 2025 FAQs