QOJ.ac

QOJ

Time Limit: 5 s Memory Limit: 512 MB Total points: 100 Hackable ✓

#14589. 七彩序列

الإحصائيات

题目描述

给出 $n$ 种颜色的小球若干,颜色的编号从 $1$ 至 $n$ ,第 $i$ 种颜色的小球共有 $a_i$ 个。小 $L$ 要把这些小球排成一个序列,使得存在一个非空前缀或非空后缀是“整齐的”。这里我们称一个前缀或后缀是“整齐的”,当且仅当其中所有 $n$ 个颜色小球的出现次数相同。你的任务是计算本质不同的序列数目。

善良的 temporaryDO 给大家指出了一些必要的说明:

  1. 一个序列长度为 $len$ 的前缀(后缀)指的是序列中最靠(右)的 $len$ 个小球。而非空前缀或后缀指的即是 $len\neq 0$ 的前缀或后缀。
  2. 对于一个小球的序列 $S$,令 $S_i$ 表示从左到右数的第 $i$ 个小球的颜色。我们认为两个小球序列 $S, T$ 本质不同,当且仅当存在一个位置 $i$ 使得 $S_i$ 不同于 $T_i$。

为了避免高精度,你只需要计算答案对 $998244353$ 取模的结果即可。

输入格式

输入的第一行包含一个整数 $n$ ,表示颜色的种类数。

接下来一行包含 $n$ 个用空格隔开的整数,第 $i$ 个正整数为 $a_i$ ,表示第 $i$ 种颜色小球的数量。

输出格式

输出包含一行一个整数,表示本质不同的小球序列数目对 $998244353$ 取模的结果。

样例一

输入

3
1 1 2

输出

2

解释

合法的两种方案分别为:1 3 3 22 3 3 1,显然,没有其他满足条件的序列。

样例二

输入

5
5 6 7 8 9

输出

322192262

子任务

测试点编号 $n=$ $a_i\le$
$1$ $2$ $500$
$2$ $2$ $2\times 10^5$
$3$ $2$ $2\times 10^5$
$4$ $50$ $2\times 10^3$
$5$ $75$ $2\times 10^3$
$6$ $100$ $2\times 10^3$
$7$ $50$ $10^5$
$8$ $75$ $1.5\times 10^5$
$9$ $90$ $1.75\times 10^5$
$10$ $100$ $2\times 10^5$

对于 $100\%$ 的数据,保证 $n \le 100$,所有 $a_i\le 200,000$ 。

在提交代码后将为你评测预测试数据并返回结果。本题的预测试数据包含 $10$ 个测试点,第 $i$ 个测试点满足表格中第 $i+1$ 行的数据规模限制。

注意:预测试数据的评测结果与最终评测结果没有关系

About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.