Not Our Problem
Time limit2sMemory limit512 MB
Count the ways to fill the -1 entries so every adjacent pair satisfies a_i * a_{i+1} * min(a_i, a_{i+1}) <= C, or print -1 if there are infinitely many.
- Level
Hard8 of 10
- Topics
- Dynamic programming, Math
- Solved
- No attempts yet
Problem
Someone (not me!) calls an array of length consisting of non-negative integers good if and only if holds for all .
Someone else (we have nothing to do with them!) gives you an array of length with some blank positions. Calculate the number of ways to fill in the blank positions so that the array is good, or determine that there are infinitely many ways. If the answer is finite, print it modulo .
Input
The first line contains two integers and (, ), the length of the array and the constraint on the product.
The second line contains the array . Each element is either , meaning it needs to be filled, or an integer between and , inclusive.
Output
If the number of ways is infinite, print . Otherwise, print the number of ways modulo .