CF1783D.Different Arrays

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:512MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given an array aa consisting of nn integers.

You have to perform the sequence of n−2n-2 operations on this array:

  • during the first operation, you either add a2a_2 to a1a_1 and subtract a2a_2 from a3a_3, or add a2a_2 to a3a_3 and subtract a2a_2 from a1a_1;
  • during the second operation, you either add a3a_3 to a2a_2 and subtract a3a_3 from a4a_4, or add a3a_3 to a4a_4 and subtract a3a_3 from a2a_2;
  • ...
  • during the last operation, you either add an−1a_{n-1} to an−2a_{n-2} and subtract an−1a_{n-1} from ana_n, or add an−1a_{n-1} to ana_n and subtract an−1a_{n-1} from an−2a_{n-2}.

So, during the ii-th operation, you add the value of ai+1a_{i+1} to one of its neighbors, and subtract it from the other neighbor.

For example, if you have the array [1,2,3,4,5][1, 2, 3, 4, 5], one of the possible sequences of operations is:

  • subtract 22 from a3a_3 and add it to a1a_1, so the array becomes [3,2,1,4,5][3, 2, 1, 4, 5];
  • subtract 11 from a2a_2 and add it to a4a_4, so the array becomes [3,1,1,5,5][3, 1, 1, 5, 5];
  • subtract 55 from a3a_3 and add it to a5a_5, so the array becomes [3,1,−4,5,10][3, 1, -4, 5, 10].

So, the resulting array is [3,1,−4,5,10][3, 1, -4, 5, 10].

An array is reachable if it can be obtained by performing the aforementioned sequence of operations on aa. You have to calculate the number of reachable arrays, and print it modulo 998244353998244353.

给你一个包含 nn 个整数的数组 aa。

你需要对该数组执行 n−2n-2 次操作,操作顺序如下:

  • 在第一次操作中,你或者将 a2a_2 加到 a1a_1 上、同时从 a3a_3 中减去 a2a_2,或者将 a2a_2 加到 a3a_3 上、同时从 a1a_1 中减去 a2a_2;
  • 在第二次操作中,你或者将 a3a_3 加到 a2a_2 上、同时从 a4a_4 中减去 a3a_3,或者将 a3a_3 加到 a4a_4 上、同时从 a2a_2 中减去 a3a_3;
  • …
  • 在最后一次操作中,你或者将 an−1a_{n-1} 加到 an−2a_{n-2} 上、同时从 ana_n 中减去 an−1a_{n-1},或者将 an−1a_{n-1} 加到 ana_n 上、同时从 an−2a_{n-2} 中减去 an−1a_{n-1}。

换言之,在第 ii 次操作中,你将 ai+1a_{i+1} 的值加到其一个相邻元素上,并从其另一个相邻元素中减去该值。

例如,若初始数组为 [1,2,3,4,5][1, 2, 3, 4, 5],一种可能的操作序列如下:

  • 从 a3a_3 中减去 22,并加到 a1a_1 上,数组变为 [3,2,1,4,5][3, 2, 1, 4, 5];
  • 从 a2a_2 中减去 11,并加到 a4a_4 上,数组变为 [3,1,1,5,5][3, 1, 1, 5, 5];
  • 从 a3a_3 中减去 55,并加到 a5a_5 上,数组变为 [3,1,−4,5,10][3, 1, -4, 5, 10]。

最终得到的数组为 [3,1,−4,5,10][3, 1, -4, 5, 10]。

若某个数组可通过上述操作序列由 aa 得到,则称其为可达数组。你需要计算可达数组的总数,并对 998244353998244353 取模后输出结果。

输入格式

The first line contains one integer nn (3≤n≤3003 \le n \le 300).

The second line contains nn integers a1,a2,…,ana_1, a_2, \dots, a_n (0≤ai≤3000 \le a_i \le 300).

第一行包含一个整数 nn(3≤n≤3003 \le n \le 300)。

第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \dots, a_n(0≤ai≤3000 \le a_i \le 300)。

输出格式

Print one integer — the number of reachable arrays. Since the answer can be very large, print its remainder modulo 998244353998244353.

输出一个整数——可达数组的个数。由于答案可能非常大,请输出其对 998244353998244353 取模的结果。

输入输出样例

  • 输入#1

    4
    1 1 1 1

    输出#1

    3
  • 输入#2

    5
    1 2 3 5 0

    输出#2

    7

输入解题思路,AI测评打分。不知道怎么写?

首页