1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
| #include<bits/stdc++.h> using namespace std;
typedef long long ll; typedef unsigned long long ull; typedef double db; typedef pair <int,int> Pii; #define reg register #define mp make_pair #define pb push_back #define Mod1(x) ((x>=P)&&(x-=P)) #define Mod2(x) ((x<0)&&(x+=P)) #define rep(i,a,b) for(int i=a,i##end=b;i<=i##end;++i) #define drep(i,a,b) for(int i=a,i##end=b;i>=i##end;--i) template <class T> inline void cmin(T &a,T b){ ((a>b)&&(a=b)); } template <class T> inline void cmax(T &a,T b){ ((a<b)&&(a=b)); }
char IO; template <class T=int> T rd(){ T s=0; int f=0; while(!isdigit(IO=getchar())) f|=IO=='-'; do s=(s<<1)+(s<<3)+(IO^'0'); while(isdigit(IO=getchar())); return f?-s:s; }
const int N=5e5+10,M=510,INF=1e9+10,P=1e9+7;
int n,m; char s[N]; int D[N],T[N];
int A[N],F[2][M],G[2][M],C[M][M]; int Pow[N]; ll qpow(ll x,ll k=P-2){ ll res=1; for(;k;k>>=1,x=x*x%P) if(k&1) res=res*x%P; return res; } int X[M],Y[M]; int Lagrange(int x,int n,int *X,int *Y){ int ans=0; rep(i,0,n) { ll s=1; rep(j,0,n) if(i!=j) s=s*(X[i]-X[j])%P; s=qpow(s); rep(j,0,n) if(i!=j) s=s*(x-X[j])%P; ans=(ans+s*Y[i])%P; } return ans; }
int main(){ freopen("angry.in","r",stdin),freopen("angry.out","w",stdout); scanf("%s",s),n=strlen(s),reverse(s,s+n); m=rd(); rep(i,0,m-1) A[i]=F[0][i]=rd(); rep(i,0,m) rep(j,*C[i]=1,i) C[i][j]=(C[i-1][j]+C[i-1][j-1])%P; int ans=0,x=2; rep(i,1,n-1) D[i-1]=x*(s[i]=='1'),x=x*2%P,T[i-1]=(s[i]=='1'); drep(i,n-1,0) D[i]+=D[i+1],Mod1(D[i]),T[i]^=T[i+1]; x=1; rep(i,0,min(m-1,n-1)) { if(s[i]=='1') { int t=1; rep(j,0,m-1) { ans=(ans+1ll*t*F[!T[i]][j])%P; t=1ll*t*D[i]%P; } } rep(d,0,1) rep(j,0,m-1) G[d][j]=F[d][j]; rep(j,*Pow=1,m-1) Pow[j]=1ll*Pow[j-1]*x%P; rep(j,0,m-1) rep(k,0,j) { F[0][k]=(F[0][k]+1ll*C[j][k]*Pow[j-k]%P*G[1][j])%P; F[1][k]=(F[1][k]+1ll*C[j][k]*Pow[j-k]%P*G[0][j])%P; } x=x*2%P; } if(m>=n) return printf("%d\n",ans),0; rep(i,0,m) { X[i]=i,x=1; rep(j,0,m-1) { Y[i]=(Y[i]+1ll*A[j]*x)%P; x=1ll*x*i%P; } if(i) Y[i]+=Y[i-1],Mod1(Y[i]); } ans=(ans+1ll*Lagrange(D[m-1]-1,m,X,Y)*(P+1)/2)%P; printf("%d\n",ans); }
|