A12819 | Natasha, Sasha and the Prefix Sums
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Natasha's favourite numbers are $n$ and $1$ , and Sasha's favourite numbers are $m$ and $-1$ . One day Natasha and Sasha met and wrote down every possible array of length $n+m$ such that some $n$ of its elements are equal to $1$ and another $m$ elements are equal to $-1$ . For each such array they counted its maximal prefix sum, probably an empty one which is equal to $0$ (in another words, if every nonempty prefix sum is less to zero, then it is considered equal to zero). Formally, denote as $f(a)$ the maximal prefix sum of an array $a_{1, \ldots ,l}$ of length $l \geq 0$ . Then:
$$$$f(a) = \max (0, \smash{\displaystyle\max_{1 \leq i \leq l}} \sum_{j=1}^{i} a_j ) $$ </p><p>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\\: 853$$$.
$$$$f(a) = \max (0, \smash{\displaystyle\max_{1 \leq i \leq l}} \sum_{j=1}^{i} a_j ) $$ </p><p>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\\: 853$$$.
输入格式
The only line contains two integers $n$ and $m$ ( $0 \le n,m \le 2\,000$ ).
输出格式
Output the answer to the problem modulo $998\: 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 $0$ .
In the second example the only possible array is \[1,1\], its maximal prefix sum is equal to $2$ .
There are $6$ 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 = 5$ .
In the second example the only possible array is \[1,1\], its maximal prefix sum is equal to $2$ .
There are $6$ 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 = 5$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted