CF1066E.Binary Numbers AND Sum

普及+/提高

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given two huge binary integer numbers aa and bb of lengths nn and mm respectively. You will repeat the following process: if b>0b \gt 0, then add to the answer the value a & ba~ \&~ b and divide bb by 22 rounding down (i.e. remove the last digit of bb), and repeat the process again, otherwise stop the process.

The value a & ba~ \&~ b means bitwise AND of aa and bb. Your task is to calculate the answer modulo 998244353998244353.

Note that you should add the value a & ba~ \&~ 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)a = 1010_2~ (10_{10}) and b=10002 (810)b = 1000_2~ (8_{10}), then the value a & ba~ \&~ b will be equal to 88, not to 10001000.

给你两个长度分别为 nn 和 mm 的极大二进制整数 aa 和 bb。你将重复执行以下过程:若 b>0b > 0,则将 a & ba~ \&~ b 的值加到答案中,并将 bb 向下取整除以 22(即移除 bb 的最后一位),然后再次重复该过程;否则停止过程。

其中 a & ba~ \&~ b 表示 aa 与 bb 的按位与运算。你的任务是计算最终答案对 998244353998244353 取模的结果。

注意:你应将 a & ba~ \&~ b 的十进制值加入答案,而非其二进制表示。因此,你的任务是以十进制形式计算答案。例如,若 a=10102 (1010)a = 1010_2~ (10_{10}) 且 b=10002 (810)b = 1000_2~ (8_{10}),则 a & ba~ \&~ b 的值为 88,而非 10001000。

输入格式

The first line of the input contains two integers nn and mm (1≤n,m≤2⋅1051 \le n, m \le 2 \cdot 10^5) — the length of aa and the length of bb correspondingly.

The second line of the input contains one huge integer aa. It is guaranteed that this number consists of exactly nn zeroes and ones and the first digit is always 11.

The third line of the input contains one huge integer bb. It is guaranteed that this number consists of exactly mm zeroes and ones and the first digit is always 11.

输入的第一行包含两个整数 nn 和 mm(1≤n,m≤2⋅1051 \le n, m \le 2 \cdot 10^5),分别表示 aa 和 bb 的长度。

输入的第二行包含一个巨大的整数 aa。保证该数恰好由 nn 个 0 和 1 组成,且首位数字恒为 11。

输入的第三行包含一个巨大的整数 bb。保证该数恰好由 mm 个 0 和 1 组成,且首位数字恒为 11。

输出格式

Print the answer to this problem in decimal notation modulo 998244353998244353.

以十进制表示输出本题的答案,并对 998244353998244353 取模。

输入输出样例

  • 输入#1

    4 4
    1010
    1101

    输出#1

    12
  • 输入#2

    4 5
    1001
    10101

    输出#2

    11

说明/提示

The algorithm for the first example:

  1. add to the answer 10102 & 11012=10002=8101010_2~ \&~ 1101_2 = 1000_2 = 8_{10} and set b:=110b := 110;
  2. add to the answer 10102 & 1102=102=2101010_2~ \&~ 110_2 = 10_2 = 2_{10} and set b:=11b := 11;
  3. add to the answer 10102 & 112=102=2101010_2~ \&~ 11_2 = 10_2 = 2_{10} and set b:=1b := 1;
  4. add to the answer 10102 & 12=02=0101010_2~ \&~ 1_2 = 0_2 = 0_{10} and set b:=0b := 0.

So the answer is 8+2+2+0=128 + 2 + 2 + 0 = 12.

The algorithm for the second example:

  1. add to the answer 10012 & 101012=12=1101001_2~ \&~ 10101_2 = 1_2 = 1_{10} and set b:=1010b := 1010;
  2. add to the answer 10012 & 10102=10002=8101001_2~ \&~ 1010_2 = 1000_2 = 8_{10} and set b:=101b := 101;
  3. add to the answer 10012 & 1012=12=1101001_2~ \&~ 101_2 = 1_2 = 1_{10} and set b:=10b := 10;
  4. add to the answer 10012 & 102=02=0101001_2~ \&~ 10_2 = 0_2 = 0_{10} and set b:=1b := 1;
  5. add to the answer 10012 & 12=12=1101001_2~ \&~ 1_2 = 1_2 = 1_{10} and set b:=0b := 0.

So the answer is 1+8+1+0+1=111 + 8 + 1 + 0 + 1 = 11.

第一个示例的算法:

  1. 将 10102 & 11012=10002=8101010_2~ \&~ 1101_2 = 1000_2 = 8_{10} 加入答案,并令 b:=110b := 110;
  2. 将 10102 & 1102=102=2101010_2~ \&~ 110_2 = 10_2 = 2_{10} 加入答案,并令 b:=11b := 11;
  3. 将 10102 & 112=102=2101010_2~ \&~ 11_2 = 10_2 = 2_{10} 加入答案,并令 b:=1b := 1;
  4. 将 10102 & 12=02=0101010_2~ \&~ 1_2 = 0_2 = 0_{10} 加入答案,并令 b:=0b := 0。

因此答案为 8+2+2+0=128 + 2 + 2 + 0 = 12。

第二个示例的算法:

  1. 将 10012 & 101012=12=1101001_2~ \&~ 10101_2 = 1_2 = 1_{10} 加入答案,并令 b:=1010b := 1010;
  2. 将 10012 & 10102=10002=8101001_2~ \&~ 1010_2 = 1000_2 = 8_{10} 加入答案,并令 b:=101b := 101;
  3. 将 10012 & 1012=12=1101001_2~ \&~ 101_2 = 1_2 = 1_{10} 加入答案,并令 b:=10b := 10;
  4. 将 10012 & 102=02=0101001_2~ \&~ 10_2 = 0_2 = 0_{10} 加入答案,并令 b:=1b := 1;
  5. 将 10012 & 12=12=1101001_2~ \&~ 1_2 = 1_2 = 1_{10} 加入答案,并令 b:=0b := 0。

因此答案为 1+8+1+0+1=111 + 8 + 1 + 0 + 1 = 11。

输入解题思路,AI测评打分。不知道怎么写?

首页