Submission #233281

#TimeUsernameProblemLanguageResultExecution timeMemory
233281kartelLjetopica (COI19_ljetopica)C++14
0 / 100
8 ms384 KiB
#include <bits/stdc++.h> //#include <ext/pb_ds/assoc_container.hpp> //#include <ext/pb_ds/tree_policy.hpp> #define in(x) freopen(x, "r", stdin) #define out(x) freopen(x, "w", stdout) #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #pragma GCC optimize("-O3") #define F first #define S second #define pb push_back #define N +100500 #define M ll(1e9 + 7) #define sz(x) (int)x.size() #define re return #define oo ll(1e18) #define el '\n' #define pii pair <int, int> using namespace std; //using namespace __gnu_pbds; //typedef tree <int, null_type, less_equal <int> , rb_tree_tag, tree_order_statistics_node_update> ordered_set; typedef long long ll; typedef long double ld; ll sm(ll x, ll y) {return (x + y) % M;} ll bp(ll x, ll y) { if (y == 0) return 1ll; if (y % 2) return (bp(x, y - 1) * x) % M; ll a = bp(x, y / 2); return (a * a) % M; } int main() { srand(time(0)); ios_base::sync_with_stdio(0); iostream::sync_with_stdio(0); ios::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); // in("input.txt"); // out("output.txt"); int n, k, i; ll ans = 0; string s, a, b; cin >> n >> k; cin >> s; cin >> a; cin >> b; if (k == 0) { bitset <1005> bt; for (i = 0; i <= n; i++) bt[i] = 0; bt[0] = 1; i = 0; while (i < n - 1) { if (s[i] == 'L') { bitset <1005> nw; for (int i = 1; i <= n; i++) nw[i] = bt[i - 1]; bt = nw; } else { bitset <1005> nw; nw[0] = 1; for (int i = 1; i <= n; i++) nw[i] = bt[i - 1]; bt = nw; } i++; } reverse(a.begin(), a.end()); reverse(b.begin(), b.end()); i = n - 1; while (i >= 0 && bt[i] == a[i] - '0') i--; // cerr << i << el; if (i < 0 || a[i] == '0') { i = n - 1; while (i >= 0 && bt[i] == b[i] - '0') i--; if (i < 0 || b[i] == '1') { i = 0; for (i = 0; i < n; i++) { if (bt[i]) ans = sm(ans, bp(2, i)); } } } for (i = 0; i <= n; i++) bt[i] = 1 - bt[i]; i = n - 1; while (i >= 0 && bt[i] == a[i] - '0') i--; if (i < 0 || a[i] == '0') { i = n - 1; while (i >= 0 && bt[i] == b[i] - '0') i--; if (i < 0 || b[i] == '1') { i = 0; for (i = 0; i < n; i++) { if (bt[i]) ans = sm(ans, bp(2, i)); } } } } cout << ans % M; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...