AT_abc473_g.Wipeout

提高+/省选-

通过率:0%

时间限制:3.00s

内存限制:1024MB

AC君温馨提醒

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

题目描述

There are NN cards arranged face down in a row, each with one of the integers 1,2,…,N1,2,\dots,N written on its face.
The order of these cards is determined uniformly at random from the N!N! possible orders.
You know that there is exactly one card with each of the integers 1,2,…,N1,2,\dots,N written on its face and that the cards were arranged uniformly at random, but you have no other information about the integers written on the faces of the cards.

You play the following game.

  • Initially, let the variable x=1x=1.
  • As long as x≤Nx \le N, repeat the following operation. One operation consists of the following three steps.
    • Specify one card and turn it face up.
    • If the integer written on the card is xx, eat that card and add 11 to xx.
    • Otherwise, turn that card face down. You can permanently remember the integer written on that card.

You always act so that the expected value of the total number of operations until all cards have been eaten is minimized.
In this case, what is the probability that the total number of operations is KK? Find it modulo 998244353998244353.

Definition of probability modulo 998244353998244353

It can be proved that the sought probability is always a rational number. Also, under the constraints of this problem, it can be proved that when the rational number to be found is expressed as an irreducible fraction PQ\frac{P}{Q}, we have Q≢0(mod998244353)Q {{}\not\equiv{}} 0 \pmod{998244353}. Therefore, there is a unique integer RR satisfying R×Q≡P(mod998244353),0≤R<998244353R \times Q \equiv P \pmod{998244353}, 0 \leq R \lt 998244353. Output this RR.

有 NN 张卡片,面朝下排成一行,每张卡片正面写有一个 1,2,…,N1,2,\dots,N 中的整数。
这些卡片的排列顺序在全部 N!N! 种可能的顺序中均匀随机选取。
你已知:每张卡片正面恰好写有 11 至 NN 中的一个整数(即所有整数各出现一次),且卡片排列是均匀随机的;除此之外,你对卡片正面所写的具体数字一无所知。

你参与如下游戏:

  • 初始时,令变量 x=1x = 1。
  • 当 x≤Nx \le N 时,重复执行以下操作。每次操作包含以下三个步骤:
    • 指定一张卡片,并将其翻至正面朝上;
    • 若该卡片正面所写的整数为 xx,则吃掉该卡片,并将 xx 增加 11;
    • 否则,将该卡片翻回背面朝下;但你可以永久记住这张卡片正面所写的数字。

你始终采取最优策略,使得“直到所有卡片均被吃掉所需的总操作次数”的期望值最小。
在此前提下,求“总操作次数恰好为 KK”的概率,并对 998244353998244353 取模。

概率对 998244353998244353 取模的定义:

可以证明,所求概率恒为有理数。此外,在本题约束条件下,可进一步证明:若将该有理数表示为既约分数 PQ\frac{P}{Q},则必有 Q≢0(mod998244353)Q {{}\not\equiv{}} 0 \pmod{998244353}。因此,存在唯一整数 RR 满足 R×Q≡P(mod998244353)R \times Q \equiv P \pmod{998244353} 且 0≤R<9982443530 \leq R < 998244353。请输出该 RR。

输入格式

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

NN KK

输入从标准输入中以如下格式给出:

NN KK

输出格式

Output the answer.

输出答案。

输入输出样例

  • 输入#1

    3 4

    输出#1

    499122177
  • 输入#2

    3 6

    输出#2

    0
  • 输入#3

    500000 777777

    输出#3

    251612105

说明/提示

Sample 1 Explanation:
For this input, N=3N=3. Let us call the cards a,b,ca,b,c in the order they are arranged.
Below is an example of your actions when acting so that the expected value of the total number of operations is minimized.

  • First, turn aa face up.
  • If 11 is written on aa, eat that card.
    • Next, turn bb face up.
    • If 22 is written on bb, eat that card.
      • Next, turn cc face up; since 33 is necessarily written on it, eat it. In this case, you eat all cards in three operations, and the probability of this happening is 1/61/6.
    • If 33 is written on bb, turn that card face down.
      • Next, turn cc face up; since 22 is necessarily written on it, eat it. After that, turn bb face up and eat it. In this case, you eat all cards in four operations, and the probability of this happening is 1/61/6.
  • If 22 is written on aa, turn that card face down.
    • Next, turn bb face up.
    • If 11 is written on bb, eat that card.
      • Next, turn aa face up and eat it. Next, turn cc face up; since 33 is necessarily written on it, eat it. In this case, you eat all cards in four operations, and the probability of this happening is 1/61/6.
    • If 33 is written on bb, turn that card face down.
      • At this point, it has become clear which integer is written on every one of the cards. So, perform three operations and eat all the cards in order of their numbers. In this case, you eat all cards in five operations, and the probability of this happening is 1/61/6.
  • If 33 is written on aa, turn that card face down.
    • Next, turn bb face up.
    • If 11 is written on bb, eat that card.
      • Next, turn cc face up; since 22 is necessarily written on it, eat it. After that, turn aa face up and eat it. In this case, you eat all cards in four operations, and the probability of this happening is 1/61/6.
    • If 22 is written on bb, turn that card face down.
      • At this point, it has become clear which integer is written on every one of the cards. So, perform three operations and eat all the cards in order of their numbers. In this case, you eat all cards in five operations, and the probability of this happening is 1/61/6.

Combining everything, the probability that the total number of operations is 33 is 1/61/6, the probability that it is 44 is 1/21/2, and the probability that it is 55 is 1/31/3.
For this sample, output 499122177499122177, which represents 1/21/2 modulo 998244353998244353.

Constraints

  • All input values are integers.
  • 1≤N≤5×1051 \le N \le 5 \times 10^5
  • N≤K≤109N \le K \le 10^9

样例 1 解释:
对于该输入,N=3N=3。我们将按排列顺序依次称这三张卡片为 a,b,ca,b,c。
以下是为使总操作次数的期望值最小而采取的一种行动方案示例:

  • 首先,将卡片 aa 翻至正面朝上。
  • 若 aa 上写有数字 11,则吃掉该卡片。
    • 接着,将卡片 bb 翻至正面朝上。
    • 若 bb 上写有数字 22,则吃掉该卡片。
      • 接着,将卡片 cc 翻至正面朝上;由于此时 cc 上必然写有数字 33,故吃掉它。此情形下,你共用 33 次操作吃掉全部卡片,发生的概率为 1/61/6。
    • 若 bb 上写有数字 33,则将该卡片翻至反面朝下。
      • 接着,将卡片 cc 翻至正面朝上;由于此时 cc 上必然写有数字 22,故吃掉它。之后,再将 bb 翻至正面朝上并吃掉。此情形下,你共用 44 次操作吃掉全部卡片,发生的概率为 1/61/6。
  • 若 aa 上写有数字 22,则将该卡片翻至反面朝下。
    • 接着,将卡片 bb 翻至正面朝上。
    • 若 bb 上写有数字 11,则吃掉该卡片。
      • 接着,将卡片 aa 翻至正面朝上并吃掉。然后,将卡片 cc 翻至正面朝上;由于此时 cc 上必然写有数字 33,故吃掉它。此情形下,你共用 44 次操作吃掉全部卡片,发生的概率为 1/61/6。
    • 若 bb 上写有数字 33,则将该卡片翻至反面朝下。
      • 此时,每张卡片上所写的整数均已确定。因此,执行三次操作,按数字大小顺序依次吃掉所有卡片。此情形下,你共用 55 次操作吃掉全部卡片,发生的概率为 1/61/6。
  • 若 aa 上写有数字 33,则将该卡片翻至反面朝下。
    • 接着,将卡片 bb 翻至正面朝上。
    • 若 bb 上写有数字 11,则吃掉该卡片。
      • 接着,将卡片 cc 翻至正面朝上;由于此时 cc 上必然写有数字 22,故吃掉它。之后,再将 aa 翻至正面朝上并吃掉。此情形下,你共用 44 次操作吃掉全部卡片,发生的概率为 1/61/6。
    • 若 bb 上写有数字 22,则将该卡片翻至反面朝下。
      • 此时,每张卡片上所写的整数均已确定。因此,执行三次操作,按数字大小顺序依次吃掉所有卡片。此情形下,你共用 55 次操作吃掉全部卡片,发生的概率为 1/61/6。

综上,总操作次数为 33 的概率为 1/61/6,为 44 的概率为 1/21/2,为 55 的概率为 1/31/3。
对于本样例,输出 499122177499122177,即 1/21/2 对 998244353998244353 取模的结果。

约束条件

  • 所有输入值均为整数。
  • 1≤N≤5×1051 \le N \le 5 \times 10^5
  • N≤K≤109N \le K \le 10^9

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

首页