#P6366. [传智杯 #2 初赛] 特殊的翻转

[传智杯 #2 初赛] 特殊的翻转

Description

Teacher k is studying the code of a virus program. This code is information consisting of a hexadecimal string of length at most 10610^6 (that is, characters 0 to 9 and A to F). Now teacher k wants to convert it into a binary 0/10/1 string (and at this time, you must ensure that the highest bit is 11). Then, perform a “flip” operation on this 0/10/1 string.

For each “flip” operation, teacher k can choose one position in the 0/10/1 string, and flip this bit and its two adjacent bits (three bits in total) separately (that is, 00 becomes 11, and 11 becomes 00). If the chosen position is at the beginning or the end of the sequence, then flip this bit and the existing adjacent bit(s).

Teacher k wants to know how to use the minimum number of “flip” steps to turn this 0/10/1 string into an all-00 string.

Input Format

A hexadecimal string consisting of 0 to 9 and A to F.

Output Format

Output the minimum number of “flip” steps needed to turn it into an all-00 string. If it is impossible to turn it into an all-00 string no matter what, output No.

15
3
FF
3
10
No

Hint

Explanation of the samples:

Hexadecimal 15 corresponds to binary 10101. By flipping positions 1/3/51/3/5, it can all become 00.

Hexadecimal FF corresponds to binary 11111111. By flipping positions 2/5/82/5/8, it can all become 00.

Hexadecimal 10 corresponds to binary 10000, and it cannot be turned into all 00.

Translated by ChatGPT 5