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

17927번 - Counting Greedily Increasing Supersequences 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 512 MB86372637.143%

문제

Given a permutation $A = (a_1, a_2, \dots, a_N)$ of the integers 1,ドル 2, \dots, N,ドル we define the greedily increasing subsequence (GIS) in the following way.

Let $g_1 = a_1$. For every $i > 1,ドル let $g_i$ be the leftmost integer in $A$ that is strictly larger than $g_{i-1}$. If for a given $i$ there is no such integer, we say that the GIS of the sequence is the sequence $(g_1, g_2, ..., g_{i - 1})$.

For example, consider the permutation $(2, 3, 1, 5, 4, 7, 6)$. First, we have $g_1 = 2$. The leftmost integer larger than 2ドル$ is 3ドル,ドル so $g_2 = 3$. The leftmost integer larger than 3ドル$ is 5ドル$ (1ドル$ is too small), so $g_3 = 5$. Finally, $g_4 = 7$. Thus, the GIS of $(2, 3, 1, 5, 4, 7, 6)$ is $(2, 3, 5, 7)$.

Given a sequence $G = (g_1, g_2, \dots, g_L),ドル how many permutations $A$ of the integers 1,ドル 2, \dots, N$ have $G$ as its GIS?

입력

The first line of input contains the integers 1ドル \le N \le 10^6,ドル the number of elements of the permutation $A,ドル and 1ドル \le L \le 10^6,ドル the length of the sequence $G$.

The next line contains $L$ positive integers between 1ドル$ and $N,ドル the elements $g_1, \dots, g_L$ of the sequence $G$.

출력

Output a single integer: the number of $N$-element permutations having the given sequence as its GIS. Since this number may be large, output it modulo the prime number 10ドル^9 + 7$.

제한

예제 입력 1

5 1
1

예제 출력 1

0

예제 입력 2

5 1
5

예제 출력 2

24

예제 입력 3

5 3
2 4 5

예제 출력 3

8

예제 입력 4

7 4
1 4 5 7

예제 출력 4

20

힌트

출처

Contest > Swedish Coding Cup > Nova Challenge 2018 D번

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

출처

대학교 대회

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

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