- 总时间限制:
- 1000ms
- 内存限制:
- 65536kB

- 描述
Given a string containing 5 digits (0-9),such as "02943", your task is to transform "12345" to it.

You have three kinds of operations as follows:

1. Exchange two adjacent digits

2. Add 1 to a digit. (9 + 1 = 0)

3. double a digit. If the result is larger than 9, then it will be the remainder of 10.

You can only use the second operation 3 times, the third operation 2 times.

Output the minimum number of operations to complete the transformation.

- 输入
- There are 100,000 cases at most.

Each cases is a string of 5 digits (0-9). - 输出
- For each case, output the minimum number of operations to transform "12345" to the given string.

If the transformation cannot be completed, output -1 - 样例输入
12435 99999 12374

- 样例输出
1 -1 3

- 提示
- If you make a search for each case, it will run out of time. It is recommended to do the pre-processing, that is, taking "12345" as the initial state to do a thorough search. In the search, you can find all the strings that can be transformed from “12345”. Remember to record the number of operations when you search.

Then for each case, you can output the result according to your record.

01 Use "long long" to calculate the answer

05 Expected Value of an Expression: Ai is less than 2^20

- 全局题号
- 15306
- 提交次数
- 78
- 尝试人数
- 22
- 通过人数
- 8