/
実行時間制限: 4 sec / メモリ制限: 512 MiB
Score: 100 points
Problem Statement
Professor JOI is a leading expert on the study of the history of IOI Kingdom. When he was surveying an old temple in IOI Kingdom, he found ruins where the stone pillars were constructed. He also found an old document which was supposedly written by ancient people in IOI Kingdom. The document contains descriptions on the stone pillars. More precisely, the following is written in the document.
- Just after the construction, there were 2N stone pillars, numbered from 1 to 2N.
- Just after the construction, for each k (1 \le k \le N), there were exactly two stone pillars of height k.
- The earthquake occurred N times. After each earthquake, some of the stone pillars collapsed and their heights decreased by 1. However, other stone pillars were protected by ancient people. These stone pillars did not collapse, and their heights remained the same.
- When an earthquake occurred, for each k (1 \le k \le N), exactly one stone pillar of height k was protected by ancient people. If there were more than one stone pillar of height k when an earthquake occurred, the stone pillar of height k with largest number was protected. In other words, if the height of the stone pillar i (1 \le i \le 2N) was h_{i} before an earthquake, then the stone pillar i was protected if and only if h_{i} \ge1 and h_{j} \ne h_{i} for every j > i.
- After the N earthquakes occurred, N stone pillars remained (i.e. there were exactly N stone pillars with height at least 1).
Professor JOI thinks it would be a great discovery if he can recover the heights of the 2N stone pillars when they were constructed. He surveyed the place where the stone pillars were constructed in more detail. He found that, after the N earthquakes occurred, the indices of the remaining stone pillars were A_{1}, A_{2}, \ldots, A_{N}.
Professor JOI wants to know the number of possible combinations of the heights of the 2N stone pillars when they were constructed. Since you are a pupil of Professor JOI, you are asked to write a program which counts this number.
Write a program which, given the indices of the remaining stone pillars after the N earthquakes occurred, calculates the number of possible combinations of the heights of the 2N stone pillars when they were constructed, modulo 1 000 000 007.
Input
Read the following data from the standard input. All the values in the input are integers.
N
A_{1} \cdots A_{N}
Output
Write one line to the standard output. Output the remainder when the answer is divided by 1 000 000 007.
Constraints
- 1 \le N \le 600.
- 1 \le A_{i} \le 2N (1 \le i \le N).
- A_{i} < A_{i+1} (1 \le i \le N - 1).
Subtasks
- (6 points) N \le 13.
- (52 points) N \le 60.
- (42 points) No additional constraints.
Sample Input and Output
Sample Input 1
3 3 4 6
Sample Output 1
5
For example, assume that the heights of the stone pillars were (2, 2, 3, 3, 1, 1), from the stone pillar 1. Since there were exactly two stone pillars of height k for each k (1 \le k \le3), it agrees with the description in the old document.
-
When the first earthquake occurred, the stone pillars 2, 4, 6 were protected by ancient people. After the first earthquake, the heights of the stone pillars became (1, 2, 2, 3, 0, 1).
-
When the second earthquake occurred, the stone pillars 3, 4, 6 were protected by ancient people. After the second earthquake, the heights of the stone pillars became (0, 1, 2, 3, 0, 1).
- When the third earthquake occurred, the stone pillars 3, 4, 6 were protected by ancient people. After the third earthquake, the heights of the stone pillars became (0, 0, 2, 3, 0, 1).
After the three earthquakes, the stone pillars 3, 4, 6 remained. It coincides with the information given in the input.
In addition to the above, there are four possible combinations of the heights of the stone pillars (2, 3, 2, 3, 1, 1), (2, 3, 3, 2, 1, 1), (3, 2, 2, 3, 1, 1), (3, 2, 3, 2, 1, 1).
Therefore, there are five possible combinations of the heights of the six stone pillars which agree with the description in the old document and the information given in the input.
Sample Input 2
1 1
Sample Output 2
0
In this sample input, (1, 1) is the only combination of the heights of the stone pillars which agrees with the description in the old document. After the first earthquake, the heights of the stone pillars became (0, 1).
Therefore, there is no possible combination of the heights of the stone pillars which agrees with the description in the old document and the information given in the input.
Sample Input 3
10 5 8 9 13 15 16 17 18 19 20
Sample Output 3
147003663
There are 111\,147\,004\,440 possible combinations of the heights of the 2N stone pillars, when they were constructed. When 111\,147\,004\,440 is divided by 1\,000\,000\,007, the remainder is 147\,003\,663. Thus, output 147\,003\,663.
配点 : 100 点
問題文
ジョイ教授は IOI 国の歴史の研究の第一人者である.IOI 国に関する神殿の調査中に,ジョイ教授は何本かの石柱が建てられた跡と古代の IOI 国の住民が書いたとされる古文書を発見した.古文書には石柱について詳しく書かれていた.具体的には以下の内容が書かれていた.
- 建設された直後には 2N 本の石柱が存在し,それぞれに 1 から 2N までの番号が付けられていた.
- 建設された直後には,高さが k (1 \leqq k \leqq N) の石柱はちょうど 2 本存在した.
- N 回の地震が発生し,各回の地震ごとに何本かの石柱が崩れて石柱の高さが 1 低くなった.ただし,一部の石柱は住民が支えていたため崩れずに高さは変わらなかった.
- 地震発生時には,それぞれの k (1 \leqq k \leqq N) について,ちょうど 1 本の高さ k の石柱が住民によって支えられた.もし地震発生時に高さ k の石柱が複数本存在する場合は,番号が最も大きい石柱が支えられた.すなわち,地震直前の石柱 i (1 \leqq i \leqq 2N) の高さを h_{i} としたとき,石柱 i が支えられる条件は,h_{i} \geqq 1,かつ,すべての j > i に対し h_{j} \ne h_{i} が成り立つことである.
- N 回の地震後に残った,すなわち高さが 1 以上である石柱は N 本であった.
建設された直後の 2N 本の石柱の高さを復元できれば世紀の大発見であると考えたジョイ教授は,石柱が建てられた跡を詳しく調査した.調査の結果,N 回の地震後に残った石柱の番号は A_{1}, A_{2}, \ldots, A_{N} であることがわかった.
この情報と古文書に書かれていたことに合致するような,建設された直後の 2N 本の石柱の高さとして考えられるのは何通り存在するのか気になったジョイ教授は,弟子であるあなたに場合の数を計算するプログラムを作るよう依頼した.
N 回の地震後に残った石柱の番号が与えられたとき,建設された直後の 2N 本の石柱の高さとして考えられる場合の数を 1\,000\,000\,007 で割ったときの余りを求めるプログラムを作成せよ.
入力
入力は以下の形式で標準入力から与えられる.入力の値はすべて整数である.
N
A_{1} \cdots A_{N}
出力
標準出力に,建設された直後の 2N 本の石柱の高さとして考えられる場合の数を 1\,000\,000\,007 で割ったときの余りを 1 行で出力せよ.
制約
- 1 \leqq N \leqq 600.
- 1 \leqq A_{i} \leqq 2N (1 \leqq i \leqq N).
- A_{i} < A_{i+1} (1 \leqq i \leqq N - 1).
小課題
- (6 点) N \leqq 13.
- (52 点) N \leqq 60.
- (42 点) 追加の制約はない.
入出力例
入力例 1
3 3 4 6
出力例 1
5
例えば,石柱の高さが石柱 1 から順に (2, 2, 3, 3, 1, 1) であったとする.高さが k (1 \leqq k \leqq 3) であるような石柱はちょうど 2 本存在するので古文書の情報と合致している.
- 1 回目の地震の際,石柱 2, 4, 6 が住民によって支えられたので,地震直後の石柱の高さは (1, 2, 2, 3, 0, 1) となる.
- 2 回目の地震の際,石柱 3, 4, 6 が住民によって支えられたので,地震直後の石柱の高さは (0, 1, 2, 3, 0, 1) となる.
- 3 回目の地震の際,石柱 3, 4, 6 が住民によって支えられたので,地震直後の石柱の高さは (0, 0, 2, 3, 0, 1) となる.
よって,3 回の地震後に残った石柱は石柱 3, 4, 6 である.これは入力で与えられた情報と合致する.
その他の石柱の高さとして考えられるのは (2, 3, 2, 3, 1, 1), (2, 3, 3, 2, 1, 1), (3, 2, 2, 3, 1, 1), (3, 2, 3, 2, 1, 1) の 4 通りのみである.
したがって,地震後に残った石柱の番号と古文書の情報に合致するような 6 本の石柱の高さは 5 通りである.
入力例 2
1 1
出力例 2
0
古文書に合致するような石柱の高さは (1, 1) のみであり,1 回の地震後の高さは (0, 1) になる.
したがって,地震後に残った石柱の番号と古文書の情報に合致するような 2 本の石柱の高さは 0 通りである.
入力例 3
10 5 8 9 13 15 16 17 18 19 20
出力例 3
147003663
建設された直後の 2N 本の石柱の高さとして考えられるものは 111\,147\,004\,440 通りあるから, 111\,147\,004\,440 を 1\,000\,000\,007 で割った余りである 147\,003\,663 を出力する.