这个题吧
你画一下就知道了
就拿这个例子来讲
4 5
1001
10101
对于b串的话第5位只会经过a串的第4位,b串的第4位会经过a串的第3位和第4位。。。。。b串的第1和第2位会经过a串的每一位
由于是&操作,计算1经过a串每一位所能带来的权值,
对b串进行处理,相加即可
#include <bits/stdc++.h> #define ll long long #define mp make_pair #define x first #define y second using namespace std; const int maxn = 2e5+10; const ll mod = 998244353; ll fac[maxn]; ll rea[maxn]; ll ans1,ans2; char a[maxn]; char b[maxn]; int main() { //freopen("in.txt","r",stdin); ll n,m; scanf("%lld%lld",&n,&m); scanf("%s %s",a,b); fac[0] = 1; for(int i = 1; i < n; ++i){ fac[i] = 2*fac[i-1]%mod; } for(int i = 0; i < n/2; ++i) { swap(a[i],a[n-1-i]); } for(int i = 0; i < m/2; ++i) { swap(b[i],b[m-1-i]); } rea[0] = 0; if(a[0] == '1') rea[0] = 1; for(int i = 1; i < n; ++i) { rea[i] = rea[i-1]; if(a[i] == '1') rea[i] = (rea[i]+fac[i]); } for(int i = 0; i < n; ++i) { if(a[1] == '1') ans1 = (ans1 + rea[i])%mod; } ll ans = 0; for(int i = 0; i < n && i < m; ++i) { if(b[i] == '1') { ans = (ans+rea[i])%mod; } } for(int i = n; i < m; ++i) { if(b[i] == '1') ans = (ans+rea[n-1])%mod; } cout << ans << endl; }