atcoder#ABC301D. [ABC301D] Bitmask
[ABC301D] Bitmask
Score : points
Problem Statement
You are given an integer and a string consisting of 0
, 1
, and ?
.
Let be the set of values that can be obtained by replacing each ?
in with 0
or 1
and interpreting the result as a binary integer.
For instance, if ?0?
, we have $T=\lbrace 000_{(2)},001_{(2)},100_{(2)},101_{(2)}\rbrace=\lbrace 0,1,4,5\rbrace$.
Print (as a decimal integer) the greatest value in less than or equal to .
If does not contain a value less than or equal to , print -1
instead.
Constraints
- is a string consisting of
0
,1
, and?
. - The length of is between and , inclusive.
- is an integer.
Input
The input is given from Standard Input in the following format:
Output
Print the answer.
?0?
2
1
As shown in the problem statement, . Among them, and are less than or equal to , so you should print the greatest of them, .
101
4
-1
We have , which does not contain a value less than or equal to .
?0?
1000000000000000000
5