#abc301d. D - Bitmask
D - Bitmask
Score : points
问题描述
给定一个整数 和一个由 0
、1
和 ?
组成的字符串 。设 是通过将 中的每个 ?
替换为 0
或 1
,并将结果解释为二进制整数所能得到的所有值的集合。例如,如果 ?0?
,我们有 $T=\lbrace 000_{(2)},001_{(2)},100_{(2)},101_{(2)}\rbrace=\lbrace 0,1,4,5\rbrace$。
输出(以十进制整数形式) 中小于等于 的最大值。如果 不包含小于等于 的值,则输出 -1
。
以上为通义千问 qwen-max 翻译,仅供参考。
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.
Sample Input 1
?0?
2
Sample Output 1
1
As shown in the problem statement, . Among them, and are less than or equal to , so you should print the greatest of them, .
Sample Input 2
101
4
Sample Output 2
-1
We have , which does not contain a value less than or equal to .
Sample Input 3
?0?
1000000000000000000
Sample Output 3
5
update @ 2024/3/10 08:27:14