#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define N 1010
#define fs first
#define sc second
#define ii pair<int,int>
#define iii pair<ii,int>
#define ld long double
#define pb push_back
#define int ll
const ll mod=1e9+7;
int mu2[N],n,k,a[N];
vector<int>l,r,dq;
ii dp[N][N][2];
void selfadd(int&u,int v)
{
u=(u+v)%mod;
}
ii get(int pos,int k,int id,int dabe)
{
if(pos==0)
return{0,(k==0)};
if(dabe&&dp[pos][k][id].fs!=-1)
return dp[pos][k][id];
ii res={0,0};
// cout<<pos<<" "<<k<<" "<<id<<endl;
//ko doi
int i=(id^a[pos]);
if(dabe||i<=dq[pos-1])
{
ii cc=get(pos-1,k,id,(dabe|(i<dq[pos-1])));
selfadd(res.fs,cc.fs+cc.sc*mu2[pos-1]*i);
selfadd(res.sc,cc.sc);
}
if(k>0)
{
i=((id^a[pos])^1);
if(dabe||i<=dq[pos-1])
{
ii cc=get(pos-1,k-1,(id^1),(dabe|(i<dq[pos-1])));
selfadd(res.fs,cc.fs+cc.sc*mu2[pos-1]*i);
selfadd(res.sc,cc.sc);
}
}
if(dabe)
dp[pos][k][id]=res;
return res;
}
int solve(vector<int>s)
{
//for(int i=n-1;i>=0;i--)cout<<s[i]<<" ";
if(s[n-1]==0)
return 0;
dq=s;
ii A=get(n-1,k,0,0),B=get(n-1,k,1,0);
selfadd(A.fs,B.fs);
selfadd(A.sc,B.sc);
return(A.fs+A.sc*mu2[n-1])%mod;
}
int32_t main()
{
// freopen("A.inp","r",stdin);
// freopen("A.out","w",stdout);
cin.tie(NULL);
cout.tie(NULL);
ios::sync_with_stdio(0);
cin>>n>>k;
for(int i=n-1;i>=1;i--)
{
char ch;
cin>>ch;
a[i]=(ch=='R');
}
mu2[0]=1;
for(int i=1;i<=n;i++)
mu2[i]=mu2[i-1]*2%mod;
l.resize(n+1,0);
r.resize(n+1,0);
for(int i=n-1;i>=0;i--)
{
char ch;
cin>>ch;
l[i]=ch-'0';
// cin>>l[i];
}
for(int i=n-1;i>=0;i--)
{
char ch;
cin>>ch;
r[i]=ch-'0';
}
for(int i=0;i<=1005;i++)
for(int j=0;j<=1005;j++)
dp[i][j][0]=dp[i][j][1]={-1,-1};
int res=solve(r);
for(int i=0;i<=n-1;i++)
if(l[i]==1)
{
l[i]=0;
for(int j=0;j<i;j++)
l[j]=1;
break;
}
cout<<(res-solve(l)+mod*mod)%mod;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
32204 KB |
Output is correct |
2 |
Correct |
13 ms |
32216 KB |
Output is correct |
3 |
Correct |
12 ms |
32212 KB |
Output is correct |
4 |
Correct |
12 ms |
32208 KB |
Output is correct |
5 |
Correct |
12 ms |
32176 KB |
Output is correct |
6 |
Correct |
12 ms |
32212 KB |
Output is correct |
7 |
Correct |
13 ms |
32216 KB |
Output is correct |
8 |
Correct |
15 ms |
32212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
32084 KB |
Output is correct |
2 |
Correct |
15 ms |
32024 KB |
Output is correct |
3 |
Correct |
12 ms |
32084 KB |
Output is correct |
4 |
Correct |
13 ms |
32084 KB |
Output is correct |
5 |
Correct |
13 ms |
32120 KB |
Output is correct |
6 |
Correct |
13 ms |
32084 KB |
Output is correct |
7 |
Correct |
13 ms |
32120 KB |
Output is correct |
8 |
Correct |
13 ms |
32084 KB |
Output is correct |
9 |
Correct |
14 ms |
32084 KB |
Output is correct |
10 |
Correct |
13 ms |
32088 KB |
Output is correct |
11 |
Correct |
13 ms |
32084 KB |
Output is correct |
12 |
Correct |
13 ms |
32112 KB |
Output is correct |
13 |
Correct |
14 ms |
32140 KB |
Output is correct |
14 |
Correct |
13 ms |
32120 KB |
Output is correct |
15 |
Correct |
16 ms |
32084 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
35 ms |
32332 KB |
Output is correct |
2 |
Correct |
25 ms |
32284 KB |
Output is correct |
3 |
Correct |
26 ms |
32208 KB |
Output is correct |
4 |
Correct |
32 ms |
32280 KB |
Output is correct |
5 |
Correct |
24 ms |
32188 KB |
Output is correct |
6 |
Correct |
32 ms |
32220 KB |
Output is correct |
7 |
Correct |
20 ms |
32212 KB |
Output is correct |
8 |
Correct |
26 ms |
32284 KB |
Output is correct |
9 |
Correct |
20 ms |
32240 KB |
Output is correct |
10 |
Correct |
27 ms |
32252 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
32204 KB |
Output is correct |
2 |
Correct |
13 ms |
32216 KB |
Output is correct |
3 |
Correct |
12 ms |
32212 KB |
Output is correct |
4 |
Correct |
12 ms |
32208 KB |
Output is correct |
5 |
Correct |
12 ms |
32176 KB |
Output is correct |
6 |
Correct |
12 ms |
32212 KB |
Output is correct |
7 |
Correct |
13 ms |
32216 KB |
Output is correct |
8 |
Correct |
15 ms |
32212 KB |
Output is correct |
9 |
Correct |
12 ms |
32084 KB |
Output is correct |
10 |
Correct |
15 ms |
32024 KB |
Output is correct |
11 |
Correct |
12 ms |
32084 KB |
Output is correct |
12 |
Correct |
13 ms |
32084 KB |
Output is correct |
13 |
Correct |
13 ms |
32120 KB |
Output is correct |
14 |
Correct |
13 ms |
32084 KB |
Output is correct |
15 |
Correct |
13 ms |
32120 KB |
Output is correct |
16 |
Correct |
13 ms |
32084 KB |
Output is correct |
17 |
Correct |
14 ms |
32084 KB |
Output is correct |
18 |
Correct |
13 ms |
32088 KB |
Output is correct |
19 |
Correct |
13 ms |
32084 KB |
Output is correct |
20 |
Correct |
13 ms |
32112 KB |
Output is correct |
21 |
Correct |
14 ms |
32140 KB |
Output is correct |
22 |
Correct |
13 ms |
32120 KB |
Output is correct |
23 |
Correct |
16 ms |
32084 KB |
Output is correct |
24 |
Correct |
35 ms |
32332 KB |
Output is correct |
25 |
Correct |
25 ms |
32284 KB |
Output is correct |
26 |
Correct |
26 ms |
32208 KB |
Output is correct |
27 |
Correct |
32 ms |
32280 KB |
Output is correct |
28 |
Correct |
24 ms |
32188 KB |
Output is correct |
29 |
Correct |
32 ms |
32220 KB |
Output is correct |
30 |
Correct |
20 ms |
32212 KB |
Output is correct |
31 |
Correct |
26 ms |
32284 KB |
Output is correct |
32 |
Correct |
20 ms |
32240 KB |
Output is correct |
33 |
Correct |
27 ms |
32252 KB |
Output is correct |
34 |
Correct |
29 ms |
32212 KB |
Output is correct |
35 |
Correct |
24 ms |
32272 KB |
Output is correct |
36 |
Correct |
26 ms |
32240 KB |
Output is correct |
37 |
Correct |
32 ms |
32204 KB |
Output is correct |
38 |
Correct |
19 ms |
32164 KB |
Output is correct |
39 |
Correct |
28 ms |
32212 KB |
Output is correct |
40 |
Correct |
18 ms |
32272 KB |
Output is correct |
41 |
Correct |
28 ms |
32232 KB |
Output is correct |
42 |
Correct |
29 ms |
32156 KB |
Output is correct |
43 |
Correct |
30 ms |
32204 KB |
Output is correct |
44 |
Correct |
40 ms |
32240 KB |
Output is correct |
45 |
Correct |
21 ms |
32272 KB |
Output is correct |
46 |
Correct |
37 ms |
32268 KB |
Output is correct |
47 |
Correct |
28 ms |
32212 KB |
Output is correct |
48 |
Correct |
23 ms |
32212 KB |
Output is correct |
49 |
Correct |
14 ms |
32188 KB |
Output is correct |
50 |
Correct |
29 ms |
32212 KB |
Output is correct |
51 |
Correct |
24 ms |
32276 KB |
Output is correct |
52 |
Correct |
24 ms |
32212 KB |
Output is correct |
53 |
Correct |
35 ms |
32212 KB |
Output is correct |
54 |
Correct |
22 ms |
32256 KB |
Output is correct |
55 |
Correct |
31 ms |
32212 KB |
Output is correct |
56 |
Correct |
31 ms |
32212 KB |
Output is correct |
57 |
Correct |
19 ms |
32204 KB |
Output is correct |
58 |
Correct |
39 ms |
32268 KB |
Output is correct |