// Why am I so dumb? :c
// chrono::system_clock::now().time_since_epoch().count()
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair<int, int> pii;
template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
const int MAXN = (int)1e3 + 5;
const int MOD = (int)1e9 + 7;
int cnt[2][2][MAXN][MAXN];
int sum[2][2][MAXN][MAXN];
string s, A, B;
int pw[MAXN];
int n, k;
int addMod(int a, int b, int m = MOD) {
a += b;
if (m <= a) {
a -= m;
}
return a;
}
int mulMod(int a, int b, int m = MOD) {
return a * 1ll * b % m;
}
void pre() {
pw[0] = 1;
for (int i = 1; i < MAXN; ++i) {
pw[i] = addMod(pw[i - 1], pw[i - 1]);
}
}
void upd(int &a, int b) {
a = addMod(a, b);
}
int L(int fl, int le, int pos, int u) {
return mulMod(sum[fl][le][pos][u], 2);
}
int R(int fl, int le, int pos, int u) {
return addMod(L(fl, le, pos, u), cnt[fl][le][pos][u]);
}
void calc(string t) {
for (int i = 0; i <= n; ++i) {
for (int j = 0; j <= n; ++j) {
for (int fl = 0; fl < 2; ++fl) {
for (int le = 0; le < 2; ++le) {
cnt[fl][le][i][j] = 0;
sum[fl][le][i][j] = 0;
}
}
}
}
if (t[0] == '0') {
return;
}
cnt[0][0][0][0] = 1;
sum[0][0][0][0] = 1;
cnt[1][0][0][0] = 1;
sum[1][0][0][0] = 1;
for (int i = 0; i < n; ++i) {
for (int j = 0; j <= k; ++j) {
// less = 1
upd(cnt[0][1][i + 1][j], cnt[0][1][i][j]);
upd(cnt[1][1][i + 1][j], cnt[1][1][i][j]);
upd(cnt[1][1][i + 1][j + 1], cnt[0][1][i][j]);
upd(cnt[0][1][i + 1][j + 1], cnt[1][1][i][j]);
// less = 0
if (s[i + 1] == 'L') {
if (t[i + 1] == '0') {
upd(cnt[0][0][i + 1][j], cnt[0][0][i][j]);
upd(cnt[0][0][i + 1][j + 1], cnt[1][0][i][j]);
}
else {
upd(cnt[0][1][i + 1][j], cnt[0][0][i][j]);
upd(cnt[0][1][i + 1][j + 1], cnt[1][0][i][j]);
upd(cnt[1][0][i + 1][j], cnt[1][0][i][j]);
upd(cnt[1][0][i + 1][j + 1], cnt[0][0][i][j]);
}
}
else {
if (t[i + 1] == '0') {
upd(cnt[1][0][i + 1][j], cnt[1][0][i][j]);
upd(cnt[1][0][i + 1][j + 1], cnt[0][0][i][j]);
}
else {
upd(cnt[0][0][i + 1][j], cnt[0][0][i][j]);
upd(cnt[0][0][i + 1][j + 1], cnt[1][0][i][j]);
upd(cnt[1][1][i + 1][j], cnt[1][0][i][j]);
upd(cnt[1][1][i + 1][j + 1], cnt[0][0][i][j]);
}
}
}
}
for (int i = 0; i < n; ++i) {
for (int j = 0; j <= k; ++j) {
if (s[i + 1] == 'L') {
upd(sum[0][1][i + 1][j], L(0, 1, i, j));
upd(sum[0][1][i + 1][j + 1], L(1, 1, i, j));
upd(sum[1][1][i + 1][j + 1], R(0, 1, i, j));
upd(sum[1][1][i + 1][j], R(1, 1, i, j));
if (t[i + 1] == '0') {
upd(sum[0][0][i + 1][j], L(0, 0, i, j));
upd(sum[0][0][i + 1][j + 1], L(1, 0, i, j));
}
else {
upd(sum[0][1][i + 1][j], L(0, 0, i, j));
upd(sum[0][1][i + 1][j + 1], L(1, 0, i, j));
upd(sum[1][0][i + 1][j], R(1, 0, i, j));
upd(sum[1][0][i + 1][j + 1], R(0, 0, i, j));
}
}
else {
upd(sum[0][1][i + 1][j], R(0, 1, i, j));
upd(sum[0][1][i + 1][j + 1], R(1, 1, i, j));
upd(sum[1][1][i + 1][j + 1], L(0, 1, i, j));
upd(sum[1][1][i + 1][j], L(1, 1, i, j));
if (t[i + 1] == '0') {
upd(sum[1][0][i + 1][j], L(1, 0, i, j));
upd(sum[1][0][i + 1][j + 1], L(0, 0, i, j));
}
else {
upd(sum[0][0][i + 1][j], R(0, 0, i, j));
upd(sum[0][0][i + 1][j + 1], R(1, 0, i, j));
upd(sum[1][1][i + 1][j], L(1, 0, i, j));
upd(sum[1][1][i + 1][j + 1], L(0, 0, i, j));
}
}
}
}
}
void solve() {
scanf("%d %d", &n, &k);
cin >> s >> A >> B;
s = '#' + s;
{
reverse(all(A));
int p = 0;
while (A[p] == '0') {
++p;
}
A[p] = '0';
for (int i = 0; i < p; ++i) {
A[p] = '1';
}
reverse(all(A));
}
int ans = 0;
calc(B);
ans = addMod(ans, sum[0][0][n - 1][k]);
ans = addMod(ans, sum[0][1][n - 1][k]);
ans = addMod(ans, sum[1][0][n - 1][k]);
ans = addMod(ans, sum[1][1][n - 1][k]);
calc(A);
ans = addMod(ans, MOD - sum[0][1][n - 1][k]);
ans = addMod(ans, MOD - sum[1][1][n - 1][k]);
printf("%d\n", ans);
}
int main() {
#ifdef IOI
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int tt = 1;
pre();
while (tt--) {
solve();
}
return 0;
}
Compilation message
ljetopica.cpp: In function 'void solve()':
ljetopica.cpp:173:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d", &n, &k);
~~~~~^~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
43 ms |
31864 KB |
Output is correct |
2 |
Correct |
41 ms |
30456 KB |
Output is correct |
3 |
Correct |
37 ms |
28664 KB |
Output is correct |
4 |
Correct |
35 ms |
27128 KB |
Output is correct |
5 |
Correct |
33 ms |
25596 KB |
Output is correct |
6 |
Correct |
30 ms |
23928 KB |
Output is correct |
7 |
Correct |
27 ms |
22396 KB |
Output is correct |
8 |
Correct |
27 ms |
20856 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
1144 KB |
Output is correct |
2 |
Correct |
3 ms |
1016 KB |
Output is correct |
3 |
Correct |
3 ms |
1144 KB |
Output is correct |
4 |
Correct |
3 ms |
1144 KB |
Output is correct |
5 |
Correct |
4 ms |
1144 KB |
Output is correct |
6 |
Correct |
3 ms |
1172 KB |
Output is correct |
7 |
Correct |
3 ms |
1144 KB |
Output is correct |
8 |
Correct |
3 ms |
1144 KB |
Output is correct |
9 |
Correct |
3 ms |
1016 KB |
Output is correct |
10 |
Correct |
3 ms |
1016 KB |
Output is correct |
11 |
Correct |
3 ms |
1016 KB |
Output is correct |
12 |
Correct |
2 ms |
1016 KB |
Output is correct |
13 |
Correct |
3 ms |
1144 KB |
Output is correct |
14 |
Correct |
3 ms |
1144 KB |
Output is correct |
15 |
Incorrect |
3 ms |
1144 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
75 ms |
31900 KB |
Output is correct |
2 |
Correct |
64 ms |
31992 KB |
Output is correct |
3 |
Correct |
67 ms |
31908 KB |
Output is correct |
4 |
Correct |
89 ms |
31864 KB |
Output is correct |
5 |
Correct |
64 ms |
31900 KB |
Output is correct |
6 |
Correct |
91 ms |
31992 KB |
Output is correct |
7 |
Correct |
55 ms |
31992 KB |
Output is correct |
8 |
Correct |
65 ms |
31864 KB |
Output is correct |
9 |
Correct |
45 ms |
31992 KB |
Output is correct |
10 |
Correct |
64 ms |
31864 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
43 ms |
31864 KB |
Output is correct |
2 |
Correct |
41 ms |
30456 KB |
Output is correct |
3 |
Correct |
37 ms |
28664 KB |
Output is correct |
4 |
Correct |
35 ms |
27128 KB |
Output is correct |
5 |
Correct |
33 ms |
25596 KB |
Output is correct |
6 |
Correct |
30 ms |
23928 KB |
Output is correct |
7 |
Correct |
27 ms |
22396 KB |
Output is correct |
8 |
Correct |
27 ms |
20856 KB |
Output is correct |
9 |
Correct |
3 ms |
1144 KB |
Output is correct |
10 |
Correct |
3 ms |
1016 KB |
Output is correct |
11 |
Correct |
3 ms |
1144 KB |
Output is correct |
12 |
Correct |
3 ms |
1144 KB |
Output is correct |
13 |
Correct |
4 ms |
1144 KB |
Output is correct |
14 |
Correct |
3 ms |
1172 KB |
Output is correct |
15 |
Correct |
3 ms |
1144 KB |
Output is correct |
16 |
Correct |
3 ms |
1144 KB |
Output is correct |
17 |
Correct |
3 ms |
1016 KB |
Output is correct |
18 |
Correct |
3 ms |
1016 KB |
Output is correct |
19 |
Correct |
3 ms |
1016 KB |
Output is correct |
20 |
Correct |
2 ms |
1016 KB |
Output is correct |
21 |
Correct |
3 ms |
1144 KB |
Output is correct |
22 |
Correct |
3 ms |
1144 KB |
Output is correct |
23 |
Incorrect |
3 ms |
1144 KB |
Output isn't correct |