I came up with a solution in $$$O(N+K^2)$$$ but idk if it can be even faster. pls tell in comments if you manage to find smt faster bc my math not very good. <3
I'll just talk about the big idea some details will be left out.
The key observation is that the array $$$b$$$ is uniquely determined by the placement of 1s inside the array.
Furthermore, in order for a $$$b$$$ to have a corresponding $$$a$$$, it is sufficient and necessary that the array $$$b$$$ contains no "alone" 1s, i.e each block of 1s must have a length of at least 2.
First, we count the number of possible such $$$b$$$ by doing simple dp(your state is length of $$$b$$$, and whether last element is 1 or not).
Now we need to handle the condition of being able to fit $$$K$$$ integers.
Consider our blocks of 1s in the array. We realize that the number of integers we can fit is at most (number of 1s)-(number of blocks).
Hence, we can brute for the number of 1s and number of blocks and do some combinatorics(how many ways to distribute the ones into the blocks multiplied by the number of ways to place the blocks such that they are not adjacent to each other) to find the number of bs that can fit less than $$$K$$$ integers
We subtract those away and we get our answer.
Here is my sub, 267980941. (i was lazy and used oeis for the first part of counting number of $$$b$$$ XD)
Thanks for reading :)
I used the same approach, but found a way to get the number of possible $$$b$$$ using combinatorics as well. I split $$$b$$$ as
pref | x1 | y1 | x2 | ... | xm | suff
wherepref
andsuff
are blocks of $$$0$$$s and can be empty, 'xi' are the blocks of $$$1$$$s (length at least 2 each). and 'yi' are blocks of $$$0$$$s (length at least 1 each). Then we can iterate over $$$m$$$, the number of blocks, and use stars and bars to count the number of different $$$b$$$.Let me try, Observe that the dp transition doesn't depend on $$$n$$$ too much, which means there exist some linear recurrence for $$$ans_{1}, ans_{2}, ...$$$, we could feed first few terms of answer (turns out 54 is enough, and it's actually $$$O(k)$$$) to Berlekamp-Messey to find its recurrence then use Bostan-Mori to compute $$$n$$$-th term of the answer, which runs in $$$O(k^2 \lg k + k \lg k \lg n)$$$.
my submission: https://codeforces.me/contest/1989/submission/268024675
Wow that's pretty cool how did you learn such techniques like Bostan-Mori btw
I just came across it someday and found it's quite interesting so I read its paper.
:o coolcool
Great
Use this approach