#TP0000057. Tòa tháp khổng lồ (A Huge Tower)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Tòa tháp khổng lồ (A Huge Tower)
A Huge Tower
Source: CEOI
Version: Phuoc Hung OJ Extended
Problem Statement
The Babylonians wish to build a tower by stacking all cubic blocks. Every block is a distinct physical object, even if two blocks have equal side lengths. Block has side length .
Blocks are stacked from bottom to top. If block is immediately above block , the side length of must not exceed the side length of plus : .
Count all valid orders of the blocks using every block exactly once. Two orders are different whenever the physical blocks occupy different positions. Output the answer modulo .
Input
- The first line contains two positive integers : the number of blocks and allowed tolerance.
- The second line contains exactly positive integers , the block side lengths.
Output
Print one integer: the number of valid tower orders modulo .
Subtasks
- Subtask 1 (20 points): ; ; for all ; all blocks are distinct even when side lengths are equal.
- Subtask 2 (30 points): ; ; for all ; all blocks are distinct even when side lengths are equal.
- Subtask 3 (50 points): ; ; for all ; all blocks are distinct even when side lengths are equal.
Examples
Input
4 1
1 2 3 100
Output
4
Explanation
There are four blocks of lengths with . The size- block must be the bottommost block. Among the six orders of the remaining three blocks, exactly four respect the tolerance between every adjacent pair; the other two put size directly above size . Therefore the answer is .