CF1204E.Natasha, Sasha and the Prefix Sums

提高+/省选-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Natasha's favourite numbers are nn and 11, and Sasha's favourite numbers are mm and −1-1. One day Natasha and Sasha met and wrote down every possible array of length n+mn+m such that some nn of its elements are equal to 11 and another mm elements are equal to −1-1. For each such array they counted its maximal prefix sum, probably an empty one which is equal to 00 (in another words, if every nonempty prefix sum is less to zero, then it is considered equal to zero). Formally, denote as f(a)f(a) the maximal prefix sum of an array a1,…,la_{1, \ldots ,l} of length l≥0l \geq 0. Then:

f(a)=max(0,smashdisplaystylemax_1leqileqlsum_j=1ia_j)f(a) = \\max (0, \\smash{\\displaystyle\\max\_{1 \\leq i \\leq l}} \\sum\_{j=1}^{i} a\_j )

Now they want to count the sum of maximal prefix sums for each such an array and they are asking you to help. As this sum can be very large, output it modulo 998 244 853998\: 244\: 853.

娜塔莎最喜爱的数字是 nn 和 11,而萨沙最喜爱的数字是 mm 和 −1-1。某天,娜塔莎和萨沙相遇了,并写下了所有长度为 n+mn+m 的数组,其中恰好有 nn 个元素等于 11,其余 mm 个元素等于 −1-1。对每个这样的数组,他们计算其最大前缀和(前缀可以为空,此时其和定义为 00;换言之,若所有非空前缀和均小于零,则最大前缀和视为 00)。形式化地,记 f(a)f(a) 为长度为 l≥0l \geq 0 的数组 a1,…,la_{1, \ldots ,l} 的最大前缀和。则:

f(a)=max⁡(0,max⁡1≤i≤l∑j=1iaj)f(a) = \max (0, \smash{\displaystyle\max_{1 \leq i \leq l}} \sum_{j=1}^{i} a_j )

现在,他们希望计算所有此类数组的最大前缀和之和,并请你帮忙求解。由于该和可能非常大,请将结果对 998 244 853998\,244\,853 取模后输出。

输入格式

The only line contains two integers nn and mm (0≤n,m≤2 0000 \le n,m \le 2\,000).

唯一的一行包含两个整数 nn 和 mm(0≤n,m≤2 0000 \le n,m \le 2\,000)。

输出格式

Output the answer to the problem modulo 998 244 853998\: 244\: 853.

将问题的答案对 998 244 853998\: 244\: 853 取模后输出。

输入输出样例

  • 输入#1

    0 2

    输出#1

    0
  • 输入#2

    2 0

    输出#2

    2
  • 输入#3

    2 2

    输出#3

    5
  • 输入#4

    2000 2000

    输出#4

    674532367

说明/提示

In the first example the only possible array is [-1,-1], its maximal prefix sum is equal to 00.

In the second example the only possible array is [1,1], its maximal prefix sum is equal to 22.

There are 66 possible arrays in the third example:

[1,1,-1,-1], f([1,1,-1,-1]) = 2

[1,-1,1,-1], f([1,-1,1,-1]) = 1

[1,-1,-1,1], f([1,-1,-1,1]) = 1

[-1,1,1,-1], f([-1,1,1,-1]) = 1

[-1,1,-1,1], f([-1,1,-1,1]) = 0

[-1,-1,1,1], f([-1,-1,1,1]) = 0

So the answer for the third example is 2+1+1+1+0+0=52+1+1+1+0+0 = 5.

在第一个例子中,唯一可能的数组是 [-1,-1],其最大前缀和等于 00。

在第二个例子中,唯一可能的数组是 [1,1],其最大前缀和等于 22。

在第三个例子中,共有 66 个可能的数组:

[1,1,-1,-1],f([1,1,-1,-1]) = 2

[1,-1,1,-1],f([1,-1,1,-1]) = 1

[1,-1,-1,1],f([1,-1,-1,1]) = 1

[-1,1,1,-1],f([-1,1,1,-1]) = 1

[-1,1,-1,1],f([-1,1,-1,1]) = 0

[-1,-1,1,1],f([-1,-1,1,1]) = 0

因此,第三个例子的答案为 2+1+1+1+0+0=52+1+1+1+0+0 = 5。

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

首页