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

25217번 - W 서브태스크다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
0.6 초 1024 MB6000.000%

문제

An array of numbers is said to be W-shaped if it meets the following conditions:

  1. It consists of four segments in decreasing order, increasing order, decreasing order, increasing order.
  2. The ordering is not strict, so increasing and decreasing segments may include consecutive equal elements.
  3. Every two consecutive segments have a common endpoint.
  4. Every segment contains at least two distinct values.

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.

제한

  • 5 ≤ N ≤ 300,000
  • Array values are integers between 1 and 1,000,000 inclusive.

서브태스크

번호배점제한
120

There are only two distinct values among the N elements.

230

All the N elements have distinct values.

350

none

예제 입력 1

5
3 1 4 2 3

예제 출력 1

6

The six distinct W-shaped permutations are:

  • 3 1 3 2 4
  • 3 1 4 2 3
  • 3 2 3 1 4
  • 3 2 4 1 3
  • 4 1 3 2 3
  • 4 2 3 1 3

예제 입력 2

7
1 2 2 2 3 4 4

예제 출력 2

72

힌트

출처

Olympiad > Romanian Master of Informatics > Romanian Master of Informatics 2018 6번

채점 및 기타 정보

  • 예제는 채점하지 않는다.
(追記) (追記ここまで)

출처

대학교 대회

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

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