CF1066E.Binary Numbers AND Sum
普及+/提高
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given two huge binary integer numbers a and b of lengths n and m respectively. You will repeat the following process: if b>0, then add to the answer the value a & b and divide b by 2 rounding down (i.e. remove the last digit of b), and repeat the process again, otherwise stop the process.
The value a & b means bitwise AND of a and b. Your task is to calculate the answer modulo 998244353.
Note that you should add the value a & b to the answer in decimal notation, not in binary. So your task is to calculate the answer in decimal notation. For example, if a=10102 (1010) and b=10002 (810), then the value a & b will be equal to 8, not to 1000.
给你两个长度分别为 n 和 m 的极大二进制整数 a 和 b。你将重复执行以下过程:若 b>0,则将 a & b 的值加到答案中,并将 b 向下取整除以 2(即移除 b 的最后一位),然后再次重复该过程;否则停止过程。
其中 a & b 表示 a 与 b 的按位与运算。你的任务是计算最终答案对 998244353 取模的结果。
注意:你应将 a & b 的十进制值加入答案,而非其二进制表示。因此,你的任务是以十进制形式计算答案。例如,若 a=10102 (1010) 且 b=10002 (810),则 a & b 的值为 8,而非 1000。
输入格式
The first line of the input contains two integers n and m (1≤n,m≤2⋅105) — the length of a and the length of b correspondingly.
The second line of the input contains one huge integer a. It is guaranteed that this number consists of exactly n zeroes and ones and the first digit is always 1.
The third line of the input contains one huge integer b. It is guaranteed that this number consists of exactly m zeroes and ones and the first digit is always 1.
输入的第一行包含两个整数 n 和 m(1≤n,m≤2⋅105),分别表示 a 和 b 的长度。
输入的第二行包含一个巨大的整数 a。保证该数恰好由 n 个 0 和 1 组成,且首位数字恒为 1。
输入的第三行包含一个巨大的整数 b。保证该数恰好由 m 个 0 和 1 组成,且首位数字恒为 1。
输出格式
Print the answer to this problem in decimal notation modulo 998244353.
以十进制表示输出本题的答案,并对 998244353 取模。
输入输出样例
输入#1
4 4 1010 1101
输出#1
12
输入#2
4 5 1001 10101
输出#2
11
说明/提示
The algorithm for the first example:
- add to the answer 10102 & 11012=10002=810 and set b:=110;
- add to the answer 10102 & 1102=102=210 and set b:=11;
- add to the answer 10102 & 112=102=210 and set b:=1;
- add to the answer 10102 & 12=02=010 and set b:=0.
So the answer is 8+2+2+0=12.
The algorithm for the second example:
- add to the answer 10012 & 101012=12=110 and set b:=1010;
- add to the answer 10012 & 10102=10002=810 and set b:=101;
- add to the answer 10012 & 1012=12=110 and set b:=10;
- add to the answer 10012 & 102=02=010 and set b:=1;
- add to the answer 10012 & 12=12=110 and set b:=0.
So the answer is 1+8+1+0+1=11.
第一个示例的算法:
- 将 10102 & 11012=10002=810 加入答案,并令 b:=110;
- 将 10102 & 1102=102=210 加入答案,并令 b:=11;
- 将 10102 & 112=102=210 加入答案,并令 b:=1;
- 将 10102 & 12=02=010 加入答案,并令 b:=0。
因此答案为 8+2+2+0=12。
第二个示例的算法:
- 将 10012 & 101012=12=110 加入答案,并令 b:=1010;
- 将 10012 & 10102=10002=810 加入答案,并令 b:=101;
- 将 10012 & 1012=12=110 加入答案,并令 b:=10;
- 将 10012 & 102=02=010 加入答案,并令 b:=1;
- 将 10012 & 12=12=110 加入答案,并令 b:=0。
因此答案为 1+8+1+0+1=11。
输入解题思路,AI测评打分。不知道怎么写?