#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
#define float double
int n, k;
string stp;
ll sum(0);
ll MOD = 1000000007;
ll mini, maxi;
ll toDecimal(string s){
ll ans(0), num(1);
for(int i=s.size()-1;i>=0;i--){
if(s[i]=='1')ans+=num;
num=num<<1;
}
return ans;
}
void dfs(ll node, int ind, bool rev){
if(ind>=stp.size()){
if(node>=mini && node<=maxi){sum = ((sum%MOD)+(node%MOD))%MOD;}
//cout<<node<<endl;
return;
}
if(stp[ind]=='R'){
if(rev){
dfs(node*2, ind+1, rev);
}
else{
dfs((node*2)+1, ind+1, rev);
}
}
else{
if(rev){
dfs((node*2)+1, ind+1, rev);
}
else{
dfs((node*2), ind+1, rev);
}
}
return;
}
int main(){
//ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin>>n>>k;
cin>>stp;
string left, right;cin>>left>>right;
mini = toDecimal(left);maxi=toDecimal(right);
dfs(1, 0, 0);
dfs(1, 0, 1);
cout<<sum<<endl;
return 0;
}
Compilation message
ljetopica.cpp: In function 'void dfs(long long int, int, bool)':
ljetopica.cpp:24:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
24 | if(ind>=stp.size()){
| ~~~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |