#P5606. Graduation Trip Permutations
Graduation Trip Permutations
Graduation Trip Permutations
You are given a travel plan for graduation with n attractions. Each attraction i has a coordinate \(a_i\). The group will visit each attraction exactly once in some order. When traveling by vehicle from an attraction at coordinate \(a\) to an attraction at coordinate \(b\), the discomfort incurred is \(a \times b\). Note that after each ride, the discomfort is reset (i.e. discomfort is not cumulative).
If for any ride the discomfort exceeds a constant \(w\) (i.e. if \(a \times b > w\)), someone will fall ill. Your task is to count the number of orders in which all attractions can be visited so that no ride causes anyone to fall ill. Output the count modulo \(998244353\).
Constraints: It is guaranteed that the number of attractions\( n \) is small enough that a solution with exponential time complexity (e.g. bitmask dynamic programming) is sufficient.
inputFormat
The first line contains two integers \(n\) and \(w\) — the number of attractions and the discomfort threshold.
The second line contains \(n\) integers \(a_1, a_2, \ldots, a_n\) representing the coordinates of the attractions.
outputFormat
Output a single integer: the number of valid orders to visit all attractions such that for every ride, the discomfort \(a \times b\) is at most \(w\) (i.e. \(a \times b \le w\)). Since the answer may be large, output it modulo \(998244353\).
sample
3 5
1 2 3
2
</p>