All Kill
Time limit1sMemory limit512 MB
Given n coding times and a contest of t minutes, find p times t^n mod 998244353, where p is the chance that all problems are coded in full, each as one contiguous block, before the end.
- Level
Hard8 of 10
- Topics
- Dynamic programming, Combinatorics, Probability
- Solved
- No attempts yet
Problem
You just finished a programming contest with your friend. You were unable to All Kill the contest (solve every problem), but you wonder whether some strategy would have solved all of them.
Solving a problem has two phases, a thinking phase and a coding phase. Your friend does all the thinking, and you do all the coding.
For each problem, you know exactly how many minutes it takes you to code it. Before you can code a problem during the contest, your friend must first get the idea for it. You do not know when that happens, so the model is this: for every problem, your friend gets the idea at a uniformly random minute during the contest. Each of these is an independent random variable. You can code only one problem at a time, so several problems may be queued at any moment. You always code the lowest numbered problem first. You work minute by minute, so you switch to a lower numbered problem if your friend gets its idea before you finish the higher numbered one. You would prefer not to switch, since context switching is expensive, even in the human brain.
Each minute proceeds as follows.
- For each problem that does not yet have an idea, your friend gets the idea with probability . Your friend can get the ideas for several problems in the same minute.
- Among the problems that still need coding time and have an idea, you take the lowest numbered one and spend the next minute coding it. If no problem qualifies, you do nothing.
Find the probability that both of the following happen together:
- Your team finishes coding all the problems by the end of the contest.
- For each problem, the minutes spent coding that problem form a contiguous interval.
Let be this probability, the number of problems, and the number of minutes in the contest. It can be shown that is an integer.
Input
The first line contains two space-separated integers () and (), where is the number of problems and is the number of minutes in the contest.
Each of the next lines contains a single integer (), the number of minutes needed to code each problem, in order. The sum of these times is at most .
Output
Output a single integer, the value of , where is the probability of the two events happening together. Note that 998,244,353 is a large prime.