#P4574. [CQOI2013] 二进制A+B

    ID: 3522 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>动态规划,dp2013重庆各省省选枚举,暴力进制

[CQOI2013] 二进制A+B

Description

You are given three integers a,b,ca, b, c and write them as binary integers without leading zeros.

For example, when a=7,b=6,c=9a=7, b=6, c=9, their binary forms are a=(111)2,b=(110)2,c=(1001)2a=(111)_2, b=(110)_2, c=(1001)_2.

Next, pad the shorter ones with leading zeros so that a,b,ca, b, c have the same number of bits as the longest one. In the example above, after padding we get a=(0111)2,b=(0110)2,c=(1001)2a=(0111)_2, b=(0110)_2, c=(1001)_2.

Finally, rearrange the bits of a,b,ca, b, c to obtain a,b,ca', b', c' such that a+b=ca' + b' = c'. In the example above, one possible rearrangement is a=(0111)2,b=(0011)2,c=(1010)2a'=(0111)_2, b'=(0011)_2, c'=(1010)_2.

Your task is to make cc' as small as possible. If there is no solution, output 1-1.

Input Format

The input contains a single line with three integers a,b,ca, b, c.

Output Format

Output a single line with the minimum value of cc'.

7 6 9
10

Hint

For all testdata, a,b,c230a,b,c \le 2^{30}.

Translated by ChatGPT 5