Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define F first
- #define S second
- //#define mp make_pair
- #define pb push_back
- using namespace std;
- typedef long long ll;
- const int MOD = 998244353;
- const int N = 5e3 + 9;
- const int M = 1e6 + 9;
- const int INF = 2e9 + 5;
- const int K = 100 + 9;
- ll nCr[N][N], res, ones[N];
- ll Flex (ll x) {
- return ((x % MOD) + MOD) % MOD;
- }
- ll calc (int l, int r) {
- return nCr[r - l + 1][ones[r] - ones[l - 1]];
- }
- int main () {
- int n, k;
- cin >> n >> k;
- string s;
- cin >> s;
- s = "3" + s;
- nCr[1][0] = nCr[1][1] = 1;
- for (int i = 2; i < N; i++) {
- nCr[i][0] = 1;
- for (int j = 1; j <= i; j++)
- nCr[i][j] = Flex (nCr[i - 1][j] + nCr[i - 1][j - 1]);
- }
- if (k == 0) {
- puts ("1");
- return 0;
- }
- for (int i = 1; i <= n; i++)
- ones[i] = ones[i - 1] + (s[i] == '1');
- if (ones[n] < k) {
- puts ("1");
- return 0;
- }
- int last = -1;
- for (int i = 1; i <= n; i++) {
- int newLast = i, cnt = 0;
- for (; newLast <= n; newLast++) {
- cnt += (s[newLast] == '1');
- if (cnt == k && newLast == n)
- break;
- if (cnt == k && s[newLast + 1] == '1')
- break;
- }
- if (newLast > n)
- break;
- res = Flex (res + calc (i, newLast));
- if (last == -1) {
- newLast = last;
- continue;
- }
- res = Flex (res - calc(i, last));
- last = newLast;
- }
- cout << res << "\n";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement