Logo
(追記) (追記ここまで)

16308번 - Entirely Unsorted Sequences 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
4 초 512 MB125795859.184%

문제

You have recently been promoted to lead scientist at NASA, the National Association for Sorting Algorithms. Congratulations! Your primary responsibility is testing the sorting algorithms that your team produces. Fortunately, NASA has a large budget this year, and you were able to buy some state of the art integers you can use to test the sorting algorithms.

As the lead scientist, you are well aware that algorithms are tested by their behaviour on worst case inputs. So, to test sorting algorithms, you need sequences that are as unsorted as possible.

Given a sequence of numbers (a1, . . . , an) we say that an element ak is sorted if for all indices j such that j > k, aj ≥ ak and for all indices j such that j < k, aj ≤ ak. For example, in

(1, 3, 2, 3, 4, 6, 5, 5)

the sorted elements are the 1, the second occurrence of 3, and the 4. Note that a sequence is sorted if and only if all its elements are sorted. A sequence is called entirely unsorted if none of its elements are sorted.

Given a sequence of integers, what is the number of entirely unsorted sequences you can make by permuting its elements? Two sequences (b1, . . . , bn) and (c1, . . . , cn) are considered to be different if there is some index i ∈ {1, . . . , n} for which bi ≠ ci. Because the number of permutations may be very large, please give it modulo 109 + 9.

입력

The input starts with an integer 1 ≤ n ≤ 5000. Then follows a single line with n integers a1, . . . , an, with 0 ≤ ai ≤ 109 for all i.

출력

Print a single integer: the number of entirely unsorted sequences you can make by permuting the ai, modulo 109 + 9.

제한

예제 입력 1

4
0 1 2 3

예제 출력 1

14

예제 입력 2

5
1 1 2 1 1

예제 출력 2

1

예제 입력 3

13
1 2 3 4 5 6 7 8 9 10 11 12 13

예제 출력 3

298600727

힌트

출처

ICPC > Regionals > Europe > Northwestern European Regional Contest > Benelux Algorithm Programming Contest > BAPC 2018 E번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /