CF1066E.Binary Numbers AND Sum

普及/提高-

通过率:0%

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 > 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 .

输入格式

The first line of the input contains two integers nn and mm ( 1n,m21051 \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 .

输出格式

Print the answer to this problem in decimal notation modulo 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 .

首页