#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("-O3")
//#pragma GCC optimize("Ofast")
#define sz(x) ll(x.size())
#define base 1000000
#define M ll(1e9+7)
#define N 100005
#define F first
#define S second
#define pb push_back
#define in insert
#define eb emplace_back
#define ed "\n"
using namespace std;
//using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
typedef short int si;
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
ll dp[1005][1005][2][2][2];
bool mk[1005][1005][2][2][2];
void dob(ll &x, ll y) {x += y; x %= M;}
ll fx(ll x, ll y) {return (x * y) % M;}
ll sm(ll x, ll y) {return (x + y) % M;}
int main()
{
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
ios_base::sync_with_stdio(0); istream::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int n, k;
cin >> n >> k;
string s;
cin >> s;
for (int i = 0; i < sz(s); i++) if (s[i] == 'L') s[i] = '0'; else s[i] = '1';
string l, r;
cin >> l >> r;
mk[0][0][1][1][0] = mk[0][0][1][1][1] = dp[0][0][1][1][0] = dp[0][0][1][1][1] = 1;
n--;
for (int i = 0; i < n; i++)
for (int j = 0; j <= k; j++)
for (int fl = 0; fl < 2; fl++)
for (int fr = 0; fr < 2; fr++)
for (int t = 0; t < 2; t++)
{
if (!mk[i][j][fl][fr][t]) continue;
if (t == 0)
{
if (fl && fr)
{
if (s[i] == '1')
{
if (r[i + 1] != '0')
{
int nfl = fl;
if (l[i + 1] == '0') nfl = 0;
dob(dp[i + 1][j][nfl][fr][t], sm(1, fx(2, dp[i][j][fl][fr][t])));
mk[i + 1][j][nfl][fr][t] = 1;
}
}
else
{
if (l[i + 1] != '1')
{
int nfr = fr;
if (r[i + 1] == '1') nfr = 0;
dob(dp[i + 1][j][fl][nfr][t], fx(2, dp[i][j][fl][fr][t]));
mk[i + 1][j][fl][nfr][t] = 1;
}
}
if (j != k)
{
if (s[i] == '0')
{
if (r[i + 1] != '0')
{
int nfl = fl;
if (l[i + 1] == '0') nfl = 0;
dob(dp[i + 1][j + 1][nfl][fr][1], sm(1, fx(2, dp[i][j][fl][fr][t])));
mk[i + 1][j + 1][nfl][fr][1] = 1;
}
}
else
{
if (l[i + 1] != '1')
{
int nfr = fr;
if (r[i + 1] == '1') nfr = 0;
dob(dp[i + 1][j + 1][fl][nfr][1], fx(2, dp[i][j][fl][fr][t]));
mk[i + 1][j + 1][fl][nfr][1] = 1;
}
}
}
}
else if (fl)
{
if (s[i] == '1')
{
int nfl = fl;
if (l[i + 1] == '0') nfl = 0;
dob(dp[i + 1][j][nfl][fr][t], sm(1, fx(2, dp[i][j][fl][fr][t])));
mk[i + 1][j][nfl][fr][t] = 1;
}
else
if (l[i + 1] != '1')
{
dob(dp[i + 1][j][fl][fr][t], fx(2, dp[i][j][fl][fr][t]));
mk[i + 1][j][fl][fr][t] = 1;
}
if (j != k)
{
if (s[i] == '0')
{
int nfl = fl;
if (l[i + 1] == '0') nfl = 0;
dob(dp[i + 1][j + 1][nfl][fr][1], sm(1, fx(2, dp[i][j][fl][fr][t])));
mk[i + 1][j + 1][nfl][fr][1] = 1;
}
else
if (l[i + 1] != '1')
{
dob(dp[i + 1][j + 1][fl][fr][1], fx(2, dp[i][j][fl][fr][t]));
mk[i + 1][j + 1][fl][fr][1] = 1;
}
}
}
else if (fr)
{
if (s[i] == '0')
{
int nfr = fr;
if (r[i + 1] == '1') nfr = 0;
dob(dp[i + 1][j][fl][nfr][t], fx(2, dp[i][j][fl][fr][t]));
mk[i + 1][j][fl][nfr][t] = 1;
}
else
if (r[i + 1] != '0')
{
dob(dp[i + 1][j][fl][fr][t], sm(1, fx(2, dp[i][j][fl][fr][t])));
mk[i + 1][j][fl][fr][t] = 1;
}
if (j != k)
{
if (s[i] == '1')
{
int nfr = fr;
if (r[i + 1] == '1') nfr = 0;
dob(dp[i + 1][j + 1][fl][nfr][1], fx(2, dp[i][j][fl][fr][t]));
mk[i + 1][j + 1][fl][nfr][1] = 1;
}
else
if (r[i + 1] != '0')
{
dob(dp[i + 1][j + 1][fl][fr][1], sm(1, fx(2, dp[i][j][fl][fr][t])));
mk[i + 1][j + 1][fl][fr][1] = 1;
}
}
}
else
{
if (s[i] == '0')
{
dob(dp[i + 1][j][fl][fr][t], fx(2, dp[i][j][fl][fr][t]));
mk[i + 1][j][fl][fr][t] = 1;
}
else
{
dob(dp[i + 1][j][fl][fr][t], sm(1, fx(2, dp[i][j][fl][fr][t])));
mk[i + 1][j][fl][fr][t] = 1;
}
if (j != k)
{
if (s[i] == '0')
{
dob(dp[i + 1][j + 1][fl][fr][1], sm(1, fx(2, dp[i][j][fl][fr][t])));
mk[i + 1][j + 1][fl][fr][1] = 1;
}
else
{
dob(dp[i + 1][j + 1][fl][fr][1], fx(2, dp[i][j][fl][fr][t]));
mk[i + 1][j + 1][fl][fr][1] = 1;
}
}
}
}
else
{
if (fl && fr)
{
if (s[i] == '0')
{
if (r[i + 1] != '0')
{
int nfl = fl;
if (l[i + 1] == '0') nfl = 0;
dob(dp[i + 1][j][nfl][fr][t], sm(1, fx(2, dp[i][j][fl][fr][t])));
mk[i + 1][j][nfl][fr][t] = 1;
}
}
else
{
if (l[i + 1] != '1')
{
int nfr = fr;
if (r[i + 1] == '1') nfr = 0;
dob(dp[i + 1][j][fl][nfr][t], fx(2, dp[i][j][fl][fr][t]));
mk[i + 1][j][fl][nfr][t] = 1;
}
}
if (j != k)
{
if (s[i] == '1')
{
if (r[i + 1] != '0')
{
int nfl = fl;
if (l[i + 1] == '0') nfl = 0;
dob(dp[i + 1][j + 1][nfl][fr][0], sm(1, fx(2, dp[i][j][fl][fr][t])));
mk[i + 1][j + 1][nfl][fr][0] = 1;
}
}
else
{
if (l[i + 1] != '1')
{
int nfr = fr;
if (r[i + 1] == '1') nfr = 0;
dob(dp[i + 1][j + 1][fl][nfr][0], fx(2, dp[i][j][fl][fr][t]));
mk[i + 1][j + 1][fl][nfr][0] = 1;
}
}
}
}
else if (fl)
{
if (s[i] == '0')
{
int nfl = fl;
if (l[i + 1] == '0') nfl = 0;
dob(dp[i + 1][j][nfl][fr][t], sm(1, fx(2, dp[i][j][fl][fr][t])));
mk[i + 1][j][nfl][fr][t] = 1;
}
else
if (l[i + 1] != '1')
{
dob(dp[i + 1][j][fl][fr][t], fx(2, dp[i][j][fl][fr][t]));
mk[i + 1][j][fl][fr][t] = 1;
}
if (j != k)
{
if (s[i] == '1')
{
int nfl = fl;
if (l[i + 1] == '0') nfl = 0;
dob(dp[i + 1][j + 1][nfl][fr][0], sm(1, fx(2, dp[i][j][fl][fr][t])));
mk[i + 1][j + 1][nfl][fr][0] = 1;
}
else
if (l[i + 1] != '1')
{
dob(dp[i + 1][j + 1][fl][fr][0], fx(2, dp[i][j][fl][fr][t]));
mk[i + 1][j + 1][fl][fr][0] = 1;
}
}
}
else if (fr)
{
if (s[i] == '1')
{
int nfr = fr;
if (r[i + 1] == '1') nfr = 0;
dob(dp[i + 1][j][fl][nfr][t], fx(2, dp[i][j][fl][fr][t]));
mk[i + 1][j][fl][nfr][t] = 1;
}
else
if (r[i + 1] != '0')
{
dob(dp[i + 1][j][fl][fr][t], sm(1, fx(2, dp[i][j][fl][fr][t])));
mk[i + 1][j][fl][fr][t] = 1;
}
if (j != k)
{
if (s[i] == '0')
{
int nfr = fr;
if (r[i + 1] == '1') nfr = 0;
dob(dp[i + 1][j + 1][fl][nfr][0], fx(2, dp[i][j][fl][fr][t]));
mk[i + 1][j + 1][fl][nfr][0] = 1;
}
else
if (r[i + 1] != '0')
{
dob(dp[i + 1][j + 1][fl][fr][0], sm(1, fx(2, dp[i][j][fl][fr][t])));
mk[i + 1][j + 1][fl][fr][0] = 1;
}
}
}
else
{
if (s[i] == '1')
{
dob(dp[i + 1][j][fl][fr][t], fx(2, dp[i][j][fl][fr][t]));
mk[i + 1][j][fl][fr][t] = 1;
}
else
{
dob(dp[i + 1][j][fl][fr][t], sm(1, fx(2, dp[i][j][fl][fr][t])));
mk[i + 1][j][fl][fr][t] = 1;
}
if (j != k)
{
if (s[i] == '1')
{
dob(dp[i + 1][j + 1][fl][fr][0], sm(1, fx(2, dp[i][j][fl][fr][t])));
mk[i + 1][j + 1][fl][fr][0] = 1;
}
else
{
dob(dp[i + 1][j + 1][fl][fr][0], fx(2, dp[i][j][fl][fr][t]));
mk[i + 1][j + 1][fl][fr][0] = 1;
}
}
}
}
}
ll ans_nakanecto = 0;
dob(ans_nakanecto, dp[n][k][0][0][0]);
dob(ans_nakanecto, dp[n][k][0][0][1]);
dob(ans_nakanecto, dp[n][k][0][1][0]);
dob(ans_nakanecto, dp[n][k][0][1][1]);
dob(ans_nakanecto, dp[n][k][1][0][0]);
dob(ans_nakanecto, dp[n][k][1][0][1]);
dob(ans_nakanecto, dp[n][k][1][1][0]);
dob(ans_nakanecto, dp[n][k][1][1][1]);
cout << ans_nakanecto << endl;
}
Compilation message
ljetopica.cpp: In function 'int main()':
ljetopica.cpp:61:63: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
mk[0][0][1][1][0] = mk[0][0][1][1][1] = dp[0][0][1][1][0] = dp[0][0][1][1][1] = 1;
~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
8448 KB |
Output is correct |
2 |
Correct |
9 ms |
8064 KB |
Output is correct |
3 |
Correct |
9 ms |
7680 KB |
Output is correct |
4 |
Correct |
8 ms |
7296 KB |
Output is correct |
5 |
Correct |
8 ms |
6912 KB |
Output is correct |
6 |
Correct |
8 ms |
6400 KB |
Output is correct |
7 |
Correct |
8 ms |
6016 KB |
Output is correct |
8 |
Correct |
7 ms |
5632 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
512 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
57 ms |
36856 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
8448 KB |
Output is correct |
2 |
Correct |
9 ms |
8064 KB |
Output is correct |
3 |
Correct |
9 ms |
7680 KB |
Output is correct |
4 |
Correct |
8 ms |
7296 KB |
Output is correct |
5 |
Correct |
8 ms |
6912 KB |
Output is correct |
6 |
Correct |
8 ms |
6400 KB |
Output is correct |
7 |
Correct |
8 ms |
6016 KB |
Output is correct |
8 |
Correct |
7 ms |
5632 KB |
Output is correct |
9 |
Incorrect |
5 ms |
512 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |