| 시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
|---|---|---|---|---|---|
| 0.6 초 | 1024 MB | 6 | 0 | 0 | 0.000% |
An array of numbers is said to be W-shaped if it meets the following conditions:
For example, the array (3 1 2 1 1 4) is W-shaped, since it consists of the segments (3 1), (1, 2), (2 1 1), (1 4). The array (3 1 2 2 2 4) is not W-shaped. It could be broken into the segments (3 1), (1 2), (2 2 2), (2 4), however the segment (2 2 2) does not contain two distinct values.
Given an array of N integers, how many distinct permutations of the array are W-shaped? Two permutations of the array, (p1 p2 ... pN) and (q1 q2 ... qN), are considered distinct if there exists a position 1 ≤ i ≤ N where pi ≠ qi. In the example above, (3 1 2 1 1 4) should only be counted once, because permuting the three 1’s does not create distinct permutations.
The first line contains N. The second line contains the N values of the array, separated by spaces.
Print a single number: the number of distinct W-shaped permutations, modulo 1,000,000,007.
| 번호 | 배점 | 제한 |
|---|---|---|
| 1 | 20 | There are only two distinct values among the N elements. |
| 2 | 30 | All the N elements have distinct values. |
| 3 | 50 | none |
5 3 1 4 2 3
6
The six distinct W-shaped permutations are:
7 1 2 2 2 3 4 4
72