#P8863. 「KDOI-03」构造数组

    ID: 9466 远端评测题 4000ms 512MiB 尝试: 0 已通过: 0 显示难度提高+/省选− 上传者: 标签>动态规划 DP2022洛谷原创O2优化动态规划优化组合数学

「KDOI-03」构造数组

Problem Description

You have an array aa of length nn. At the beginning, all aia_i are 00. You are given a target array bb of the same length nn. Determine how many different ways there are such that, after performing the following operation several times, array aa can be turned into bb.

  • Choose two different indices 1≤i<j≤n1\leq i<j\leq n, and increase both aia_i and aja_j by 11.

Two ways are considered different if and only if there exists some xx such that, in the xx-th operation, the chosen pair of indices (i,j)(i,j) in one way is different from that in the other way.

Take the answer modulo 998244353\bm{998244353}.

Input Format

Read input from standard input.

The input consists of two lines.

The first line contains a positive integer nn.

The second line contains nn positive integers, representing b1,b2,…,bnb_1,b_2,\ldots,b_n.

Output Format

Write output to standard output.

Output one line containing one positive integer, representing the number of ways to transform array aa into array bb using the operations, modulo 998244353998244353.

4
2 2 2 2
90

Hint

[Sample 1 Explanation]

Type ID First group Second group Third group Fourth group Number of ways
11 1<->2 3<->4 (42)=6\binom{4}{2}=6
22 1<->3 2<->4
33 1<->4 1<->4 2<->3 2<->3
44 1<->2 3<->4 4!=244!=24
55 1<->3 2<->4
66 1<->3 1<->4 2<->3 2<->4

The total number of ways is 6×3+24×3=906\times3+24\times3=90.

[Sample 2]

See array/array2.in and array/array2.ans in the contestant files.

This sample satisfies the constraints of test points 6∼86\sim8.

[Sample 3]

See array/array3.in and array/array3.ans in the contestant files.

This sample satisfies the constraints of test points 12∼1412\sim14.

[Sample 4]

See array/array4.in and array/array4.ans in the contestant files.

This sample satisfies the constraints of test points 15∼1815\sim18.

[Sample 5]

See array/array5.in and array/array5.ans in the contestant files.

This sample satisfies the constraints of test points 19∼2019\sim20.

[Sample 6]

See array/array6.in and array/array6.ans in the contestant files.

This sample satisfies the constraints of test points 21∼2221\sim22.

[Sample 7]

See array/array7.in and array/array7.ans in the contestant files.

This sample satisfies the constraints of test points 23∼2523\sim25.


[Constraints]

For 100%100\% of the data, 1≤n≤5 0001\le n\le5~000, 1≤bi≤3×1041\leq b_i\le3 \times 10^4, and ∑bi≤3×104\sum b_i\le3 \times 10^4.

Test point ID nn ∑bi\sum b_i
11 ≤5 000\leq5~000 ≡1(mod2)\equiv 1\pmod 2
2∼32\sim3 =1=1 ≤3×104\leq3 \times 10^4
4∼54\sim5 =2=2
6∼86\sim8 ≤5\leq5 ≤8\leq8
9∼119\sim11 ≤20\leq20 =n=n
12∼1412\sim14 ≤5 000\leq 5~000
15∼1815\sim18 ≤16\leq16
19∼2019\sim20 ≤700\le 700 ≤700\le700
21∼2221\sim22 ≤5 000\le 5~000 ≤5 000\le5~000
23∼2523\sim25 ≤5 000\le5~000 ≤3×104\le3 \times 10^4

Translated by ChatGPT 5