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# (.NET Core 3.1.201) (judge verdict: Wrong Answer)

using System;
using System.Linq;
using System.Collections.Generic;
using Debug = System.Diagnostics.Trace;
using SB = System.Text.StringBuilder;
using static System.Math;
using static Program.IO.Scanner;
using Number = System.Int64;
using System.Numerics;
#region IO
namespace Program.IO {
	using System.IO;
	using System.Text;
	using System.Globalization;

	public class Printer : StreamWriter {
		public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } }
		public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) { }
	}
	static public class Scanner {
		public static StreamScanner sc = new StreamScanner(Console.OpenStandardInput());
		public static int ri => sc.Integer();
		public static long rl => sc.Long();
		public static string rs => sc.Scan();
		public static double rd => sc.Double();
	}
	public class StreamScanner {
		public StreamScanner(Stream stream) { str = stream; }

		public readonly Stream str;
		private readonly byte[] buf = new byte[1024];
		private int len, ptr;
		public bool isEof = false;
		public bool IsEndOfStream { get { return isEof; } }

		private byte read() {
			if (isEof) return 0;
			if (ptr >= len) {
				ptr = 0;
				if ((len = str.Read(buf, 0, 1024)) <= 0) {
					isEof = true;
					return 0;
				}
			}
			return buf[ptr++];
		}

		public char Char() {
			byte b = 0;
			do b = read(); while ((b < 33 || 126 < b) && !isEof);
			return (char)b;
		}
		public string Scan() {
			var sb = new StringBuilder();
			for (var b = Char(); b >= 33 && b <= 126; b = (char)read()) sb.Append(b);
			return sb.ToString();
		}
		public string ScanLine() {
			var sb = new StringBuilder();
			for (var b = Char(); b != '\n' && b != 0; b = (char)read()) if (b != '\r') sb.Append(b);
			return sb.ToString();
		}
		public long Long() { return isEof ? long.MinValue : long.Parse(Scan()); }
		public int Integer() { return isEof ? int.MinValue : int.Parse(Scan()); }
		public double Double() { return isEof ? double.NaN : double.Parse(Scan(), CultureInfo.InvariantCulture); }
	}

}

#endregion

#region main
static class Ex {
	static public string AsString(this IEnumerable<char> ie) { return new string(ie.ToArray()); }
	static public string AsJoinedString<T>(this IEnumerable<T> ie, string st = " ") {
		return string.Join(st, ie);
	}

	static public void Main() {
		Console.SetOut(new Program.IO.Printer(Console.OpenStandardOutput()) { AutoFlush = false });
		var solver = new Program.Solver();
		var t = new System.Threading.Thread(solver.Solve, 50000000);
		t.Start();
		t.Join();
		//*/
		//solver.Solve();
		Console.Out.Flush();
	}
}
#endregion

namespace Program {
	public class Solver {
		Random rnd = new Random(0);
		public void Solve() {
		var s=rs+'0';
		var k=ri;
		
		k=1000000;
var a=new List<int>();
var cnt=0;
foreach (var x in s)
{
	if(x=='0'){a.Add(cnt);cnt=0;}
	else cnt++;
	
}
var sum = a.Sum();
k=Min(k,sum);
Debug.WriteLine(a.AsJoinedString());
var dp =Enumerate(k+5,x=>new ModInt[k+5]);
dp[0][0]=1;
foreach (var x in a)
{
	//Debug.WriteLine("------");
	var next =Enumerate(k+5,y=>new ModInt[k+5]);
	for (int i = k; i >=0; i--)
	for (int j = k; j >=0; j--)if(dp[i][j].num!=0){
		//Debug.WriteLine($"{i} {j} {dp[i][j]}");
		next[i][j]+=dp[i][j];
		//ここを累積和でまとめる
		for (int ni = i+1; ni <= k; ni++)next[ni][j]+=dp[i][j];
		for (int nj = j+1; nj<=i&&nj <= k&&nj-j<=x; nj++)next[i][nj]+=dp[i][j];
		
	}
	dp=next;
}
ModInt ans=0;
for (int i = 0; i <= k; i++)ans+=dp[i][i];
Console.WriteLine(ans);
		}
		const long INF = 1L << 60;
		static int[] dx = { -1, 0, 1, 0 };
		static int[] dy = { 0, 1, 0, -1 };
		static T[] Enumerate<T>(int n, Func<int, T> f) {
			var a = new T[n]; for (int i = 0; i < a.Length; ++i) a[i] = f(i); return a;
		}
		static T[][] Enumerate<T>(int n, int m, Func<int, int, T> f) {
			return Enumerate(n, x => Enumerate(m, y => f(x, y)));
		}
		static public void Swap<T>(ref T a, ref T b) { var tmp = a; a = b; b = tmp; }
	}
}

	#region ModInt
	/// <summary>
	/// [0,<see cref="Mod"/>) までの値を取るような数
	/// </summary>
	public struct ModInt {
		public const long Mod = (int)998244353;
		public long num;
		public ModInt(long n) { num = n; }
		public override string ToString() { return num.ToString(); }
		public static ModInt operator +(ModInt l, ModInt r) { return new ModInt(l.num + r.num < Mod ? l.num + r.num : l.num + r.num - Mod); }
		public static ModInt operator -(ModInt l, ModInt r) { return new ModInt(l.num + Mod - r.num < Mod ? l.num + Mod - r.num : l.num - r.num); }
		public static ModInt operator *(ModInt l, ModInt r) { return new ModInt(l.num * r.num % Mod); }
		public static ModInt operator /(ModInt l, ModInt r) { return l * Inverse(r); }
		public static implicit operator ModInt(long n) { return n.mod(); }
		public static ModInt Pow(ModInt v, long k) { return Pow(v.num, k); }
		public static ModInt Pow(long v, long k) {
			long ret = 1;
			for (k %= Mod - 1; k > 0; k >>= 1, v = v * v % Mod)
				if ((k & 1) == 1) ret = ret * v % Mod;
			return new ModInt(ret);
		}
		public static ModInt Inverse(ModInt v) { return Pow(v, Mod - 2); }
	}
	public static partial class ModIntEx {
		public static ModInt mod(this long v) {
			v %= ModInt.Mod;
			if (v < 0) v += ModInt.Mod;
			return new ModInt(v);
		}
		public static ModInt mod(this int v) {
			var u = v % ModInt.Mod;
			if (u < 0) u += ModInt.Mod;
			return new ModInt(u);
		}
		public static ModInt m(this long v) { return new ModInt(v); }
		public static ModInt m(this int v) { return new ModInt(v); }
	}
	#endregion