Portal: http://codeforces.com/contest/1066/problem/E
Meaning of the questions: two binary numbers a, b, each time the results of a & b summation, b right one, continue summing the results of a & b until b == 0
a, b length <= 2e5, the result of modulo 998 244 353
This question ideas and ideas consistent with a particular question brush, quickly thought,
a & b, bitwise and, when a [i] == 1 && b [j] == 1 upon application of the power of the bit weight of 2
eg
543210
a 100101
b 10111
years + = 2 ^ 0 + 2 ^ 2
b right one
543210
a 100101
b 1011
……
Found that a fixed, from 0 to the number of bits corresponding to "1" in each of a "1" bit, b, statistics, multiplied by a power of 2, the corresponding bit can be friends
To engage in a suffix and b, traversing a, can be summed statistics
#include<algorithm> #include<iostream> #include<cstdio> #include<cstdlib> #include<cmath> #include<cstring> #include<string> #include<map> #include<queue> #include<stack> #include<list> #include<set> using namespace std; typedef long long ll; typedef pair<ll,ll> P; typedef long double ld; #define mem(x) memset(x, 0, sizeof(x)) #define me(x) memset(x, -1, sizeof(x)) #define fo(i,n) for(i=0; i<n; i++) #define sc(x) scanf("%I64d", &x) #define sca(n,m) scanf("%lld%lld", &n, &m) #define pr(x) printf("%I64d\n", x) #define pri(x) printf("%lld ", x) #define lowbit(x) x&-x const ll MOD = 998244353; const ll oo = 1e18; const ll N = 2e6 + 5; ll sum[N]; int main() { ll i, j, k; ll n, m, t; cin>>n>>m; string s,p; cin>>s>>p; for(i=m-1; i>=0; i--) { if(p[i]=='1') k=1; else k=0; sum[i]=sum[i+1]+k; } k=1; ll ans=0; for(i=n-1, j=m-1; i>=max(0ll,n-m); i--,j--) { if(s[i]=='1') ans+=(sum[0]-sum[j+1])*k, ans%=MOD; k*=2;k%=MOD; } cout<<ans<<endl; return 0; }