AtCoder Regular Contest 162
E
Strange Constraints
AtCoder
⌀ 2780
原题
← DF →
翻译中…

Problem Statement

翻译中…

You are given a sequence of length $N$ consisting of integers from $1$ to $N$, $A=(A_1,A_2,\ldots,A_N)$.

翻译中…

Find the number, modulo $998244353$, of sequences of length $N$ consisting of integers from $1$ to $N$, $B=(B_1,B_2,\ldots,B_N)$, that satisfy the following conditions for all $i=1,2,\ldots,N$.

翻译中…
  • The number of occurrences of $i$ in $B$ is at most $A_i$.
  • The number of occurrences of $B_i$ in $B$ is at most $A_i$.
翻译中…

Constraints

翻译中…
  • $1 \leq N \leq 500$
  • $1 \leq A_i \leq N$
  • All input values are integers.
翻译中…

Input

翻译中…

The input is given from Standard Input in the following format:

翻译中…

N
A_1 A_2 \ldots A_N

翻译中…

Output

翻译中…

Print the answer.

翻译中…

样例

Input #1
3
1 2 3
Output #1
10
The following $10$ sequences satisfy the conditions: - $(1,2,2)$ - $(1,2,3)$ - $(1,3,2)$ - $(1,3,3)$ - $(2,1,3)$ - $(2,3,1)$ - $(2,3,3)$ - $(3,1,2)$ - $(3,2,1)$ - $(3,2,2)$
Input #2
4
4 4 4 4
Output #2
256
All sequences of length $4$ consisting of integers from $1$ to $4$ satisfy the conditions, and there are $4^4=256$ such sequences.
Input #3
5
1 1 1 1 1
Output #3
120
All permutations of $(1,2,3,4,5)$ satisfy the conditions, and there are $5!=120$ such sequences.
Input #4
14
6 5 14 3 6 7 3 11 11 2 3 7 8 10
Output #4
628377683
Be sure to print the number modulo $998244353$.
题目信息
题号
arc162_e
时间限制
3 s
内存限制
1024 MB

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。