AtCoder Beginner Contest 463
G
随机游走距离
Random Walk Distance
AtCoder
⌀ 2452
原题
← F→

随机游走距离AI (CI翻译)

Problem Statement

题目描述

AI (CI翻译)

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 $\frac{P}{Q}$, we have $Q {{}\not\equiv{}} 0 \pmod{998244353}$. Therefore, there is a unique integer $R$ satisfying $R \times Q \equiv P \pmod{998244353}, 0 \leq R < 998244353$. Find this $R$.

给定一个正整数 $N$ 和一个整数 $X$。

高桥位于数轴上的坐标 $0$ 处。现在,他将执行以下移动 $N$ 次:

  • 当位于坐标 $x$ 时,以相同的概率选择坐标 $x-1$ 或坐标 $x+1$,并移动到该坐标。

$N$ 次移动中选择目的地的过程相互独立。设完成所有移动后所在的坐标为 $x'$。求 $|x'-X|$ 的期望值对 $998244353$ 取模后的结果。

给定 $T$ 个测试用例,请分别求解。

模 $998244353$ 的期望值定义

可以证明,所求的期望值始终是有理数。此外,在本题的约束条件下,可以证明将其表示为最简分数 $\frac{P}{Q}$ 时,有 $Q {{}\not\equiv{}} 0 \pmod{998244353}$。因此,满足 $R \times Q \equiv P \pmod{998244353}$ 且 $0 \leq R < 998244353$ 的整数 $R$ 唯一存在。请求出该 $R$。AI (CI翻译)

Constraints

约束条件

AI (CI翻译)
  • $1 \leq T \leq 2 \times 10^5$
  • $1 \leq N \leq 2 \times 10^5$
  • $|X| \leq 2 \times 10^5$
  • All input values are integers.
  • $1 \leq T \leq 2 \times 10^5$
  • $1 \leq N \leq 2 \times 10^5$
  • $|X| \leq 2 \times 10^5$
  • 所有输入值均为整数。
AI (CI翻译)

Input

输入格式

AI (CI翻译)

The input is given from Standard Input in the following format:

输入从标准输入按以下格式给出:AI (CI翻译)

T
\mathrm{case}_1
\mathrm{case}_2
\vdots
\mathrm{case}_T

T
\mathrm{case}_1
\mathrm{case}_2
\vdots
\mathrm{case}_T
AI (CI翻译)

Each $\mathrm{case}_i$ is the $i$-th test case and is given in the following format:

每个 $\mathrm{case}_i$ 表示第 $i$ 个测试用例,其格式如下:AI (CI翻译)

N X

N X
AI (CI翻译)

Output

输出格式

AI (CI翻译)

Output $T$ lines. The $i$-th line should contain the answer for the $i$-th test case.

输出 $T$ 行。第 $i$ 行应包含第 $i$ 个测试用例的答案。AI (CI翻译)

样例

Input #1
5
3 2
6 4
2026 -620
12345 67890
98765 -43210
Output #1
748683267
935854085
270602660
67890
844852181
For the first test case, Takahashi ends up at coordinate $-3$ with probability $\frac{1}{8}$, at coordinate $-1$ with probability $\frac{3}{8}$, at coordinate $1$ with probability $\frac{3}{8}$, and at coordinate $3$ with probability $\frac{1}{8}$. Thus, the expected value of $|x'-X|$ is $\frac{1}{8}\cdot|{-3}-2|+\frac{3}{8}\cdot|{-1}-2|+\frac{3}{8}\cdot|1-2|+\frac{1}{8}\cdot|3-2|=\frac{9}{4}$.
题目信息
题号
abc463_g
时间限制
3 s
内存限制
1024 MB

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(gpt-6.1-sol),如有出入请以原文为准。