#include <bits/stdc++.h>
using namespace std;
unsigned long long n,k;
string path;
string a;
string b;
unsigned long long aval=0;
unsigned long long bval=0;
unsigned long long rez=0;
set<unsigned long long> s;
void solve(unsigned long long start,unsigned long long k,unsigned long long n,bool chk)
{
if(n==path.size())
{
if(!s.count(start) && start>=aval && start<=bval)
{
rez+=start;
rez%=1000000007;
s.insert(start);
//cout << start << endl;
}
return;
}
if(k==0)
{
if(!chk)
{
if(path[n]=='L')solve(2*start,k,n+1,chk);
else
{
solve(2*start+1,k,n+1,chk);
}
}
else
{
if(path[n]=='R')solve(2*start,k,n+1,chk);
else
{
solve(2*start+1,k,n+1,chk);
}
}
}
else
{
if(!chk)
{
solve(2*start,k,n+1,chk);
solve(2*start+1,k-1,n+1,chk^1);
}
else
{
solve(2*start+1,k,n+1,chk);
solve(2*start,k-1,n+1,chk^1);
}
}
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n >> k;
cin >> path;
cin >> a;
cin >> b;
unsigned long long br=0;
for(unsigned long long i=a.size()-1;i>=0;i--)
{
if(a[i]=='1')aval+=(1<<br);
br++;
}
br=0;
for(unsigned long long i=b.size()-1;i>=0;i--)
{
if(b[i]=='1')bval+=(1<<br);
br++;
}
solve(1,k,0,0);
solve(1,k,0,1);
cout << rez;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
3 ms |
504 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
3 ms |
376 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
3 ms |
504 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
3 ms |
504 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |