This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#define LL long long
#define fr(x) freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);
using namespace std;
const int N=1e3+5,mod=1e9+7;
int n,m,f[N][N][2][2],g[N][N][2][2],L[N],R[N],pw[N],dis[N];
string A,B,C;
inline int md(int x){return x>=mod?x-mod:x;}
inline int sol(int *R)
{
if(!R[0]) return 0;
memset(f,0,sizeof(f));memset(g,0,sizeof(g));
f[0][0][0][1]=g[0][0][0][1]=f[0][0][1][1]=g[0][0][1][1]=1;
for(int i=1;i<n;i++) for(int j=0;j<=m;j++)
for(int o=0;o<2;o++) for(int p=0;p<2;p++) for(int w=0;w<2;w++)
{
int F=f[i-1][j][o][p],G=g[i-1][j][o][p];
int J=j+w,O=o^w,nw=dis[i]^O;
if(p&&nw>R[i]) continue;int P=p&(nw==R[i]);
f[i][J][O][P]=md(f[i][J][O][P]+F);
g[i][J][O][P]=(g[i][J][O][P]+2ll*G+nw*F)%mod;
}
int ans=0;
for(int o=0;o<2;o++) for(int p=0;p<2;p++) ans=md(ans+g[n-1][m][o][p]);
return ans;
}
int main()
{
// fr(maze)
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);cin>>n>>m>>C;
for(int i=pw[0]=1;i<=n;i++) pw[i]=md(pw[i-1]<<1);
for(int i=1;i<n;i++) dis[i]=(C[i-1]=='R');
cin>>A>>B;
for(int i=0;i<n;i++) L[i]=A[i]-'0',R[i]=B[i]-'0';
for(int i=n-1;~i;i--) if(L[i]){L[i]=0;for(int j=i+1;j<n;j++) L[j]=1;break;}
return cout<<(sol(R)-sol(L)+mod)%mod,0;
}
Compilation message (stderr)
ljetopica.cpp: In function 'int sol(int*)':
ljetopica.cpp:19:4: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
19 | if(p&&nw>R[i]) continue;int P=p&(nw==R[i]);
| ^~
ljetopica.cpp:19:28: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
19 | if(p&&nw>R[i]) continue;int P=p&(nw==R[i]);
| ^~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |