1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
| #include <iostream> #include <algorithm> #include <cstring> #include <cstdio>
using namespace std;
const int Max_n = 3e+6 + 5;
typedef long long Int64;
struct Segment { int l, r; Segment(int l_ = 0, int r_ = 0):l(l_),r(r_){} bool operator < (const Segment &Rhs) const { return (l == Rhs.l) ? (r < Rhs.r) : (l < Rhs.l); } }s[Max_n]; char Mode[Max_n]; int ptr, n, a, b, p, m;
inline void add(int l1, int l2, int r1, int r2) { if (l1) s[++ptr] = Segment(0, l1); if (l2 < r1) s[++ptr] = Segment(l2, r1); if (r2 < n) s[++ptr] = Segment(r2, n); }
int main() { scanf("%d%d%d%d%d", &n, &a, &b, &p, &m); scanf("%s", Mode); for (int i = 0, t = b; i < m; ++i, t = (t + a) % n) { if (Mode[i] == '0') add(0, max(p - t, 0), n - t, min(n - t + p, n)); else add(max(p - t, 0), n - t, min(n - t + p, n), n); } for (int i = n - 1, t = n - a; i > n - m; --i, t = (t - a + n) % n) s[++ptr] = Segment(t, t + 1); s[++ptr] = Segment(n, n + 1); sort(s + 1, s + 1 + ptr); int lst = 0, ans = 0; for (int i = 1; i <= ptr; ++i) { if (s[i].l > lst) ans += s[i].l - lst, lst = s[i].r; else lst = max(lst, s[i].r); } printf("%d\n", ans); return 0; }
|