Submission #131114

#TimeUsernameProblemLanguageResultExecution timeMemory
131114BTheroLjetopica (COI19_ljetopica)C++17
100 / 100
91 ms31992 KiB
// 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 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 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; 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; while (tt--) { solve(); } return 0; }

Compilation message (stderr)

ljetopica.cpp: In function 'void solve()':
ljetopica.cpp:163:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d", &n, &k);
     ~~~~~^~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...