AT_arc232_d.Delete Different

NOI/NOI+/CTSC

通过率:0%

时间限制:2.00s

内存限制:1024MB

AC君温馨提醒

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

题目描述

You are given integers NN and KK.

For an integer sequence SS consisting of integers between 11 and KK, inclusive, define its score f(S)f(S) as follows.

  • Repeat the following operation until all elements of SS are equal. The number of times this operation is performed is f(S)f(S).

    • Let ∣S∣|S| be the length of SS before the operation. For every ii satisfying 2≤i≤∣S∣2 \leq i \leq |S| and Si−1≠SiS_{i-1} \ne S_i, simultaneously delete the ii-th element of SS. Concatenate the remaining elements in their original order to form the new SS.

There are KNK^N integer sequences SS of length NN consisting of integers between 11 and KK, inclusive. Find the sum of f(S)f(S) over all of them, modulo 998244353998244353.

给你整数 NN 和 KK。

对于一个由 11 到 KK(含)之间的整数组成的整数序列 SS,定义其得分 f(S)f(S) 如下:

  • 重复执行以下操作,直到 SS 中所有元素均相等。该操作执行的次数即为 f(S)f(S)。

    • 设操作前 SS 的长度为 ∣S∣|S|。对每个满足 2≤i≤∣S∣2 \leq i \leq |S| 且 Si−1≠SiS_{i-1} \ne S_i 的下标 ii,同时删除 SS 的第 ii 个元素。将剩余元素按原顺序拼接,得到新的 SS。

共有 KNK^N 个长度为 NN、且每个元素均在 11 到 KK(含)之间的整数序列 SS。求所有这些序列的 f(S)f(S) 之和,并对 998244353998244353 取模。

输入格式

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

NN KK

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

NN KK

输出格式

Output the answer.

输出答案。

输入输出样例

  • 输入#1

    3 2

    输出#1

    8
  • 输入#2

    6 2

    输出#2

    126
  • 输入#3

    2 2

    输出#3

    2
  • 输入#4

    10 3

    输出#4

    145002
  • 输入#5

    100 998244352

    输出#5

    139448523

说明/提示

Sample 1 Explanation:
The scores of (1,1,1)(1,1,1) and (2,2,2)(2,2,2) are 00, and the scores of (1,2,2)(1,2,2) and (2,1,1)(2,1,1) are 22. The scores of the other four sequences are 11, so the sum is 88.

Sample 2 Explanation:
For example, S=(1,2,2,2,1,2)S=(1,2,2,2,1,2) changes as follows, so its score is 33.

(1,2,2,2,1,2)→(1,2,2)→(1,2)→(1)(1,2,2,2,1,2) \to (1,2,2) \to (1,2) \to (1)

Constraints

  • 2≤N≤1002 \leq N \leq 100
  • 2≤K<9982443532 \leq K < 998244353
  • All input values are integers.

样例 1 解释:
序列 (1,1,1)(1,1,1) 和 (2,2,2)(2,2,2) 的得分为 00,序列 (1,2,2)(1,2,2) 和 (2,1,1)(2,1,1) 的得分为 22。其余四个序列的得分均为 11,因此总和为 88。

样例 2 解释:
例如,序列 S=(1,2,2,2,1,2)S=(1,2,2,2,1,2) 按如下方式变化,故其得分为 33。

(1,2,2,2,1,2)→(1,2,2)→(1,2)→(1)(1,2,2,2,1,2) \to (1,2,2) \to (1,2) \to (1)

约束条件

  • 2≤N≤1002 \leq N \leq 100
  • 2≤K<9982443532 \leq K < 998244353
  • 所有输入值均为整数。

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

首页