National Olympiad in Informatics, China, 2014
In the 21st century, many people have contracted an odd disorder – getting-up syndrome. Symptoms include having great difficulty getting out of bed in the morning and feeling out of sorts even after getting up. As a generally high-spirited teenager, ATM has been struggling with getting-up syndrome. Through extensive research, he has found the cause of the disorder. On the vast seabeds of the Pacific Ocean, there lives a giant dragon by the name of DRD who holds the essence of sleep itself and can extend everyone's sleeping time at his will. So with DRD's every movement, getting-up syndrome intensifies for everyone, growing at a frightening rate to affect more and more people in the world. To put an end to this terrible malady, ATM has decided to travel to the seabed of the Pacific and slay this evil dragon once and for all.
After untold hardships, ATM has finally reached DRD's resting place. He
now braces for the arduous battle that lies ahead. DRD has a very
special tactic. His line of defense involves transforming the attack
power of the opponent using a series of calculations to minimize the
damage done to himself. Roughly speaking, DRD's line of defense consists
of OR
, XOR
, or
AND
, while the parameter is guaranteed to be a nonnegative integer. If
one's power before going through a defense gate is
Since ATM's skill is limited, the initial attack power of his strike can
only be an integer between
Input Specification
The first line contains two integers
The next
Output Specification
Output one line consisting of a single integer, representing the maximum possible damage that ATM could do to DRD in one strike.
Sample Input
3 10
AND 5
OR 6
XOR 7
Sample Output
1
Explanation
ATM can choose any one of the numbers
If he chooses
4 AND 5 = 4
4 OR 6 = 6
6 XOR 7 = 1
Similarly, we can calculate to find out that initial striking powers of
Constraints
Test Case | Guarantees | Notes | |
---|---|---|---|
1 |
OR , XOR , AND |
||
2 |
|
||
3 | |||
4 | One gate with AND 0 will exist. | ||
5 | All gates will have the same operator. | ||
6 | |||
7 |
|
All gates will have the same operator. | |
8 | |||
9 | |||
10 |
Hint
For this problem, competitors will have to first convert operands into binary. If two operands have different number of digits, then the shorter operand must be padded with leading 0's before carrying out the operation.
OR
is the bitwise OR operation. For two binary operands of equal
length, pairs of corresponding digits will yield a result of 1 if
either digit is 1, otherwise a result 0.
XOR
is the bitwise XOR operation. For two binary operands of equal
length, pairs of corresponding digits will yield a result of 1 if
the digits are different (distinct), otherwise a result 0.
AND
is the bitwise AND operation. For two binary operands of equal
length, pairs of corresponding digits will yield a result of 1 if
both digits are 1, otherwise a result 0.
For example, we can perform the OR
, XOR
, and AND
operations on
the decimal values 5 and 3, resulting in the following:
0101 (5 in base-10)
OR 0011 (3 in base-10)
= 0111 (7 in base-10)
0101 (5 in base-10)
XOR 0011 (3 in base-10)
= 0110 (6 in base-10)
0101 (5 in base-10)
AND 0011 (3 in base-10)
= 0001 (1 in base-10)
Problem translated to English by .
Comments