AT_abc463_g.Random Walk Distance
省选/NOI-
通过率:0%
时间限制:3.00s
内存限制:1024MB
AC君温馨提醒
该题目为【atcoder】题库的题目,您提交的代码将被提交至atcoder进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given a positive integer N and an integer X.
Takahashi is at coordinate 0 on a number line. He will now perform the following move N times:
- When at coordinate x, choose coordinate x−1 or coordinate x+1 with equal probability and move there.
The choices of destination across the N moves are all independent. Let x′ be the coordinate after all N moves. Find the expected value, modulo 998244353, of ∣x′−X∣.
You are given T test cases; solve each of them.
Definition of expected value modulo 998244353
It can be proved that the sought expected value is always a rational number. Moreover, under the constraints of this problem, it can be proved that when expressed as an irreducible fraction QP, we have Q≡0(mod998244353). Therefore, there is a unique integer R satisfying R×Q≡P(mod998244353),0≤R<998244353. Find this R.
给定一个正整数 N 和一个整数 X。
高桥位于数轴上的坐标 0 处。他将执行以下操作共 N 次:
- 当前位于坐标 x 时,以相等的概率选择坐标 x−1 或 x+1,并移动到该位置。
这 N 次移动中每次的选择相互独立。设 N 次移动后最终坐标为 x′。求 ∣x′−X∣ 的期望值对 998244353 取模的结果。
你将得到 T 组测试用例,请分别求解每组。
期望值对 998244353 取模的定义
可以证明:所求期望值恒为有理数。此外,在本题约束下,可进一步证明:若将该期望值表示为既约分数 QP,则必有 Q≡0(mod998244353)。因此,存在唯一整数 R 满足 R×Q≡P(mod998244353) 且 0≤R<998244353。请输出该 R。
输入格式
The input is given from Standard Input in the following format:
T
case1
case2
⋮
caseT
Each casei is the i-th test case and is given in the following format:
N X
输入从标准输入中按以下格式给出:
T
case1
case2
⋮
caseT
每个 casei 表示第 i 个测试用例,其格式如下:
N X
输出格式
Output T lines. The i-th line should contain the answer for the i-th test case.
输出 T 行。第 i 行应包含第 i 个测试用例的答案。
输入输出样例
输入#1
5 3 2 6 4 2026 -620 12345 67890 98765 -43210
输出#1
748683267 935854085 270602660 67890 844852181
说明/提示
Sample 1 Explanation:
For the first test case, Takahashi ends up at coordinate −3 with probability 81, at coordinate −1 with probability 83, at coordinate 1 with probability 83, and at coordinate 3 with probability 81. Thus, the expected value of ∣x′−X∣ is 81⋅∣−3−2∣+83⋅∣−1−2∣+83⋅∣1−2∣+81⋅∣3−2∣=49.
Constraints
- 1≤T≤2×105
- 1≤N≤2×105
- ∣X∣≤2×105
- All input values are integers.
样例 1 解释:
对于第一个测试用例,高桥最终位于坐标 −3 的概率为 81,位于坐标 −1 的概率为 83,位于坐标 1 的概率为 83,位于坐标 3 的概率为 81。因此,∣x′−X∣ 的期望值为
81⋅∣−3−2∣+83⋅∣−1−2∣+83⋅∣1−2∣+81⋅∣3−2∣=49.
限制条件
- 1≤T≤2×105
- 1≤N≤2×105
- ∣X∣≤2×105
- 所有输入值均为整数。
输入解题思路,AI测评打分。不知道怎么写?