AmazonOA #181
Find Number of Ways to Group Parcels (Also for Amazon Japan)
Estimated HardJudge-ready
Topics (AI-labelled)Bits & MathHashing
Each package has its own identity, so packages are distinct even when their weights are equal. Split all packages into unordered pairs, using every package exactly once; the absolute weight difference within each pair must be wt. Find the number of complete groupings modulo 1000000007, and return 0 if no complete grouping exists. A clause in the original text about "the number of single pairs" contradicts the main statement and the complete-grouping example whose output is 6; this site explicitly adopts the meaning of the main statement and that example, i.e. pairing up all packages.
Input
The first line contains n wt; the second line contains the weights. This site uses 1≤n≤100000, 0≤wt≤10^9, weights 1..10^9.
Output
Output a single integer, the answer.
Example 1
Input:
8 1
4 5 5 4 4 5 2 3
Output:
6
Example 2
Input:
4 0
1 1 1 1
Output:
3
Example 3
Input:
3 1
1 2 3
Output:
0
Example notes
The answers are 6, 3 and 0.
Editorial
Loading solution…