#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define F first
#define S second
#define pb push_back
#define endl "\n"
#define aint(x) x.begin(), x.end()
const int M = 3007;
const ll inf = 2e9;
const ll mod = 1e9 + 7;
const double pi = acos(-1);
const double eps = 1e-6;
const int dx[] = {0, -1, 0, 1}, dy[] = {1, 0, -1, 0};
const int block = 320;
string s, a, b;
ll n, k, mn, mx;
ll solve(ll i, ll rem, ll cost, bool flip){
if(rem < 0) return 0;
if(i == n - 1){
if(rem || cost < mn || cost > mx) return 0ll;
return cost;
}
ll ret = 0;
if(flip){
if(s[i] == 'L') ret = (solve(i + 1, rem - 1, cost * 2 + 1, flip ^ 1) + solve(i + 1, rem, cost * 2 + 1, flip)) % mod;
else ret = (solve(i + 1, rem - 1, cost * 2, flip ^ 1) + solve(i + 1, rem, cost * 2, flip)) % mod;
}
else{
if(s[i] == 'R') ret = (solve(i + 1, rem - 1, cost * 2 + 1, flip ^ 1) + solve(i + 1, rem, cost * 2 + 1, flip)) % mod;
else ret = (solve(i + 1, rem - 1, cost * 2, flip ^ 1) + solve(i + 1, rem, cost * 2, flip)) % mod;
}
return ret;
}
int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n >> k >> s >> a >> b;
for(int i = 0; i < n; ++i){
mn = mn * 2 + a[i] - '0';
mx = mx * 2 + b[i] - '0';
}
cout << (solve(0, k, 1, 1) + solve(0, k, 1, 0)) % mod << endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
316 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
28 ms |
212 KB |
Output is correct |
2 |
Correct |
9 ms |
212 KB |
Output is correct |
3 |
Correct |
142 ms |
296 KB |
Output is correct |
4 |
Correct |
150 ms |
332 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
27 ms |
300 KB |
Output is correct |
7 |
Correct |
3 ms |
332 KB |
Output is correct |
8 |
Correct |
141 ms |
296 KB |
Output is correct |
9 |
Correct |
11 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
320 KB |
Output is correct |
11 |
Correct |
10 ms |
212 KB |
Output is correct |
12 |
Correct |
5 ms |
212 KB |
Output is correct |
13 |
Correct |
144 ms |
332 KB |
Output is correct |
14 |
Correct |
19 ms |
212 KB |
Output is correct |
15 |
Correct |
37 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1089 ms |
340 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
316 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |