Problem:
Score : 800 points

Problem Statement

Given is a string S consisting of 0 and 1. Find the number of strings, modulo 998244353, that can result from applying the following operation on S between 0 and K times (inclusive):

Choose a pair of integers i, j (1\leq i < j\leq |S|) such that the i-th and j-th characters of S are 0 and 1, respectively. Remove the j-th character from S and insert it to the immediate left of the i-th character.

Constraints

1 \leq |S| \leq 300

0 \leq K \leq 10^9

S consists of 0 and 1.

Input

Input is given from Standard Input in the following format:

S K

Output

Find the number of strings, modulo 998244353, that can result from applying the operation on S between 0 and K times (inclusive).

Sample Input 1

0101 1

Sample Output 1

4

Four strings, 0101, 0110, 1001, and 1010, can result.

Sample Input 2

01100110 2

Sample Output 2

14

Sample Input 3

1101010010101101110111100011011111011000111101110101010010101010101 20

Sample Output 3

113434815

Solution in C++ (GCC 9.2.1) (judge verdict: Wrong Answer)

#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 998244353;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

template <class T, class U>
vector<T> make_v(U size, const T& init){ return vector<T>(static_cast<size_t>(size), init); }

template<class... Ts, class U>
auto make_v(U size, Ts... rest) { return vector<decltype(make_v(rest...))>(static_cast<size_t>(size), make_v(rest...)); }

template<class T> void chmin(T &a, const T &b){ a = (a < b ? a : b); }
template<class T> void chmax(T &a, const T &b){ a = (a > b ? a : b); }

template<u32 M = 1000000007>
struct modint{
    u32 val;
    modint(): val(0){}
    template<typename T>
    modint(T t){t %= (T)M; if(t < 0) t += (T)M; val = t;}

    modint pow(ll k) const {
        modint res(1), x(val);
        while(k){
            if(k&1) res *= x;
            x *= x;
            k >>= 1;
        }
        return res;
    }
    template<typename T>
    modint& operator=(T t){t %= (T)M; if(t < 0) t += (T)M; val = t; return *this;}
    modint inv() const {return pow(M-2);}
    modint& operator+=(modint a){val += a.val; if(val >= M) val -= M; return *this;}
    modint& operator-=(modint a){if(val < a.val) val += M-a.val; else val -= a.val; return *this;}
    modint& operator*=(modint a){val = (u64)val*a.val%M; return *this;}
    modint& operator/=(modint a){return (*this) *= a.inv();}
    modint operator+(modint a) const {return modint(val) +=a;}
    modint operator-(modint a) const {return modint(val) -=a;}
    modint operator*(modint a) const {return modint(val) *=a;}
    modint operator/(modint a) const {return modint(val) /=a;}
    modint operator-(){return modint(M-val);}
    bool operator==(const modint a) const {return val == a.val;}
    bool operator!=(const modint a) const {return val != a.val;}
    bool operator<(const modint a) const {return val < a.val;}
};
using mint = modint<MOD>;

int main() {
    string s; int K;
    cin >> s >> K;
    reverse(s.begin(),s.end());
    vector<int> v;
    int val = 0, cnt = 0;
    for (auto &&i : s) {
        if(i == '0'){
            v.emplace_back(val);
            val = 0;
        }else {
            val++;
        }
    }
    v.emplace_back(val);
    int n = v.size();
    auto dp1 = make_v(n+1, n+1, n+1, mint(0)), dp2 = make_v(n+1, n+1, n+1, mint(0));
    dp1[0][0][0] = 1;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j <= n; ++j) {
            for (int k = 0; k <= n; ++k) {
                dp1[i+1][j][k] += dp1[i][j][k];
                int x = min(max(j+v[i]+1, k+v[i]+1), n+1);
                if(x != n+1) dp1[i+1][j+v[i]+1][k+v[i]+1] -= dp1[i][j][k];
                dp2[i+1][0][k] += dp1[i][j][k];
                dp2[i+1][j][k] -= dp1[i][j][k];
            }
        }
        for (int j = 0; j <= n; ++j) {
            for (int k = 0; k <= n; ++k) {
                if(j && k) dp1[i+1][j][k] += dp1[i+1][j-1][k-1];
                if(j) dp2[i+1][j][k] += dp2[i+1][j-1][k];
            }
        }
        for (int j = 0; j <= n; ++j) {
            for (int k = 0; k <= n; ++k) {
                dp1[i+1][j][k] += dp2[i+1][j][k];
            }
        }
    }
    mint ans = 0;
    for (int k = 0; k <= min(K, n); ++k) {
        ans += dp1.back()[0][k];
    }
    cout << ans.val << "\n";
    return 0;
}