CF2255F.Who Will Witness the End?
NOI/NOI+/CTSC
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Before her final sortie, Chtholly asks Willem three questions.
The third is this: when the end finally comes, who will remain to witness it?
Willem cannot answer her directly. Instead, he draws a circle on the board, calling it the ring of all things, and writes down n labeled integers a1,a2,…,an. Every possible order around the ring describes a different way in which the world might reach its end.
Consider a permutation p1,p2,…,pn of the integers from 1 to n. Place the corresponding numbers on a circle in this order. The weight of the resulting circular arrangement is
prod_i=1n(a_p_i+a_p_i+1),
where pn+1=p1.
Two permutations describe the same circular arrangement if one can be obtained from the other by a cyclic shift. Reversing an arrangement does not make it the same arrangement; in other words, reflected arrangements are considered different unless they also coincide after a cyclic shift.
Find the sum of the weights of all distinct circular arrangements. Since the answer may be large, output it modulo 998244353.
在她最后一次出击之前,克洛伊向威尔姆提出了三个问题。
第三个问题是:当终结最终到来之时,谁将留下见证这一切?
威尔姆无法直接回答她。相反,他在黑板上画了一个圆,称之为“万物之环”,并在其上写下了 n 个带标签的整数 a1,a2,…,an。环上每一种可能的排列顺序,都对应着世界走向终结的一种不同方式。
考虑 1 到 n 的一个排列 p1,p2,…,pn。将对应的数字按此顺序放置在一个圆上。该环形排列的权重定义为:
i=1∏n(api+api+1),
其中约定 pn+1=p1。
若一个排列可通过另一个排列进行循环移位得到,则这两个排列描述的是同一个环形排列。但将环形排列翻转(即取镜像)并不会使其与原排列相同;换言之,反射后的排列被视为不同的排列,除非它还能通过某个循环移位与原排列重合。
请计算所有互不相同的环形排列的权重之和。由于答案可能很大,请输出其对 998244353 取模的结果。
输入格式
Each test contains multiple test cases. The first line contains the number of test cases t (1≤t≤104). The description of the test cases follows.
The first line of each test case contains one integer n (3≤n≤2⋅105) — the number of labeled integers.
The second line contains n integers a1,a2,…,an (0≤ai<998244353).
It is guaranteed that the sum of n over all test cases does not exceed 2⋅105.
每个测试包含多个测试用例。第一行包含测试用例的数量 t(1≤t≤104)。随后是测试用例的描述。
每个测试用例的第一行包含一个整数 n(3≤n≤2⋅105)—— 表示带标签的整数个数。
第二行包含 n 个整数 a1,a2,…,an(0≤ai<998244353)。
保证所有测试用例的 n 之和不超过 2⋅105。
输出格式
For each test case, output one integer — the sum of the weights of all distinct circular arrangements, modulo 998244353.
对于每个测试用例,输出一个整数——所有不同的环形排列的权重之和,对 998244353 取模。
输入输出样例
输入#1
3 3 1 2 3 6 0 1 0 1 0 1 10 114514 1919810 350234 11831 314159265 271828182 123456789 998244352 5201314 23333333
输出#1
120 12 265885269
说明/提示
In the first test case, there are two distinct circular arrangements. They can be represented by the permutations [1,2,3] and [1,3,2]. Both have weight
(1+2)(2+3)(3+1)=60,
so the answer is 120.
In the second test case, an arrangement has nonzero weight only if zeros and ones alternate around the circle. There are
frac2cdot3!cdot3!6=12
such circular arrangements: the factor 2 chooses whether a linear representative starts with a zero or a one, and division by 6 identifies cyclic shifts. Each arrangement has weight 1. All other arrangements have weight 0, so the answer is 12.
在第一个测试用例中,存在两种不同的环形排列。它们可分别由排列 [1,2,3] 和 [1,3,2] 表示。两者的权值均为
(1+2)(2+3)(3+1)=60,
因此答案为 120。
在第二个测试用例中,仅当 0 和 1 在圆周上交替出现时,排列才具有非零权值。满足该条件的环形排列共有
62⋅3!⋅3!=12
种:因子 2 用于选择线性表示形式是以 0 还是以 1 开头,除以 6 是为了将循环移位视为同一排列。每种排列的权值均为 1。其余所有排列的权值均为 0,因此答案为 12。
输入解题思路,AI测评打分。不知道怎么写?