#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define MOD 1000000007
ll n ,k , c1 = 0, c2 = 0;
string s;
ll ch(ll u , ll rem , ll c , ll curr){
if(rem < 0 or (u == n - 1 and (rem > 0 or c < c1 or c > c2))){
return 0;
}
if(u == n - 1){
return c;
}
if(curr){
if(s[u] == 'L'){
return (ch(u + 1, rem - 1, c * 2 + 1, 1 - curr) + ch(u + 1, rem, c * 2 + 1, curr)) % MOD;
}
else{
return (ch(u + 1, rem - 1, c * 2, 1 - curr) + ch(u + 1, rem, c * 2, curr)) % MOD;
}
}
else{
if(s[u] == 'R'){
return (ch(u + 1, rem - 1, c * 2 + 1, 1 - curr) + ch(u + 1, rem, c * 2 + 1, curr)) % MOD;
}
else{
return (ch(u + 1, rem - 1, c * 2, 1 - curr) + ch(u + 1, rem, c * 2, curr)) % MOD;
}
}
}
void solve(){
cin >> n >> k;
string a , b;
cin >> s >> a >> b;
for(int i = 0 ;i < a.length(); i ++){
c1 = ((c1 * 2) + (a[i] - '0')) % MOD;
c2 = ((c2 * 2) + (b[i] - '0')) % MOD;
}
if(k == 0){
if(c1 == c2){
c1 = 0 ;
}
cout << (c1 + c2) % MOD << '\n';
}
else{
cout << (ch(0 , k, 1 ,0) + ch(0 , k, 1 ,1)) % MOD << '\n';
}
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int tests = 1;
// cin >> tests;
for (int i = 1; i <= tests; i++){
solve();
}
return 0;
}
Compilation message
ljetopica.cpp: In function 'void solve()':
ljetopica.cpp:36:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
36 | for(int i = 0 ;i < a.length(); i ++){
| ~~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
504 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
38 ms |
344 KB |
Output is correct |
2 |
Correct |
10 ms |
348 KB |
Output is correct |
3 |
Correct |
209 ms |
424 KB |
Output is correct |
4 |
Correct |
258 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
33 ms |
348 KB |
Output is correct |
7 |
Correct |
4 ms |
348 KB |
Output is correct |
8 |
Correct |
255 ms |
432 KB |
Output is correct |
9 |
Correct |
14 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
448 KB |
Output is correct |
11 |
Correct |
15 ms |
456 KB |
Output is correct |
12 |
Correct |
10 ms |
452 KB |
Output is correct |
13 |
Correct |
226 ms |
344 KB |
Output is correct |
14 |
Correct |
27 ms |
456 KB |
Output is correct |
15 |
Correct |
73 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1100 ms |
344 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
504 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
38 ms |
344 KB |
Output is correct |
10 |
Correct |
10 ms |
348 KB |
Output is correct |
11 |
Correct |
209 ms |
424 KB |
Output is correct |
12 |
Correct |
258 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
33 ms |
348 KB |
Output is correct |
15 |
Correct |
4 ms |
348 KB |
Output is correct |
16 |
Correct |
255 ms |
432 KB |
Output is correct |
17 |
Correct |
14 ms |
344 KB |
Output is correct |
18 |
Correct |
1 ms |
448 KB |
Output is correct |
19 |
Correct |
15 ms |
456 KB |
Output is correct |
20 |
Correct |
10 ms |
452 KB |
Output is correct |
21 |
Correct |
226 ms |
344 KB |
Output is correct |
22 |
Correct |
27 ms |
456 KB |
Output is correct |
23 |
Correct |
73 ms |
348 KB |
Output is correct |
24 |
Execution timed out |
1100 ms |
344 KB |
Time limit exceeded |
25 |
Halted |
0 ms |
0 KB |
- |