CF1909I.Short Permutation Problem

普及+/提高

通过率:0%

时间限制:7.00s

内存限制:1024MB

AC君温馨提醒

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

题目描述

Xomu - Last Dance

⠀

You are given an integer nn.

For each (m,k)(m, k) such that 3≤m≤n+13 \leq m \leq n+1 and 0≤k≤n−10 \leq k \leq n-1, count the permutations of [1,2,...,n][1, 2, ..., n] such that pi+pi+1≥mp_i + p_{i+1} \geq m for exactly kk indices ii, modulo 998 244 353998\,244\,353.

Xomu - 最后一支舞

⠀

给定一个整数 nn。

对所有满足 3≤m≤n+13 \leq m \leq n+1 且 0≤k≤n−10 \leq k \leq n-1 的 (m,k)(m, k),统计 [1,2,...,n][1, 2, ..., n] 的排列 pp 的个数,使得恰好有 kk 个下标 ii 满足 pi+pi+1≥mp_i + p_{i+1} \geq m。答案对 998 244 353998\,244\,353 取模。

输入格式

The input consists of a single line, which contains two integers nn, xx (2≤n≤40002 \leq n \leq 4000, 1≤x<1 000 000 0071 \leq x \lt 1\,000\,000\,007).

输入仅包含一行,其中包含两个整数 nn 和 xx(2≤n≤40002 \leq n \leq 4000,1≤x<1 000 000 0071 \leq x \lt 1\,000\,000\,007)。

输出格式

Let am,ka_{m,k} be the answer for the pair (m,k)(m, k), modulo 998 244 353998\,244\,353.

Let $$\large S = \sum_{m=3}^{n+1} \sum_{k=0}^{n-1} a_{m,k}x^{mn+k}\phantom{0}.$$

Output a single line with an integer: SS modulo 1 000 000 0071\,000\,000\,007.

Note that using two different modulos is intentional. We want you to calculate all the am,ka_{m,k} modulo 998 244 353998\,244\,353, then treat them like integers in the range [0,998 244 352][0, 998\,244\,352], and hash them modulo 1 000 000 0071\,000\,000\,007.

令 am,ka_{m,k} 表示对数 (m,k)(m, k) 的答案,对 998 244 353998\,244\,353 取模。

令 $$\large S = \sum_{m=3}^{n+1} \sum_{k=0}^{n-1} a_{m,k}x^{mn+k}\phantom{0}.$$

输出一行一个整数:SS 对 1 000 000 0071\,000\,000\,007 取模的结果。

注意,此处使用两个不同的模数是有意为之。你需要先将所有 am,ka_{m,k} 对 998 244 353998\,244\,353 取模,再将它们视为取值范围为 [0,998 244 352][0, 998\,244\,352] 的整数,并对 1 000 000 0071\,000\,000\,007 取模(即“哈希”)。

输入输出样例

  • 输入#1

    3 2

    输出#1

    77824
  • 输入#2

    4 1000000000

    输出#2

    30984329
  • 输入#3

    8 327869541

    输出#3

    85039220
  • 输入#4

    4000 1149333

    输出#4

    584870166

说明/提示

In the first test case, the answers for all (m,k)(m, k) are shown in the following table:

k=0k = 0

k=1k = 1

k=2k = 2

m=3m = 3

00

00

66

m=4m = 4

00

44

22

  • The answer for (m,k)=(3,2)(m, k) = (3, 2) is 66, because for every permutation of length 33, ai+ai+1≥3a_i + a_{i+1} \geq 3 exactly 22 times.
  • The answer for (m,k)=(4,2)(m, k) = (4, 2) is 22. In fact, there are 22 permutations of length 33 such that ai+ai+1≥4a_i + a_{i+1} \geq 4 exactly 22 times: [1,3,2][1, 3, 2], [2,3,1][2, 3, 1].

Therefore, the value to print is 29⋅0+210⋅0+211⋅6+212⋅0+213⋅4+214⋅2≡77 8240(mod01 000 000 007)2^9 \cdot 0 + 2^{10} \cdot 0 + 2^{11} \cdot 6 + 2^{12} \cdot 0 + 2^{13} \cdot 4 + 2^{14} \cdot 2 \equiv 77\,824 \phantom{0} (\text{mod} \phantom{0} 1\,000\,000\,007).

In the second test case, the answers for all (m,k)(m, k) are shown in the following table:

k=0k = 0

k=1k = 1

k=2k = 2

k=3k = 3

m=3m = 3

00

00

00

2424

m=4m = 4

00

00

1212

1212

m=5m = 5

00

44

1616

44

  • The answer for (m,k)=(5,1)(m, k) = (5, 1) is 44. In fact, there are 44 permutations of length 44 such that ai+ai+1≥5a_i + a_{i+1} \geq 5 exactly 11 time: [2,1,3,4][2, 1, 3, 4], [3,1,2,4][3, 1, 2, 4], [4,2,1,3][4, 2, 1, 3], [4,3,1,2][4, 3, 1, 2].

In the third test case, the answers for all (m,k)(m, k) are shown in the following table:

k=0k = 0

k=1k = 1

k=2k = 2

k=3k = 3

k=4k = 4

k=5k = 5

k=6k = 6

k=7k = 7

m=3m = 3

00

00

00

00

00

00

00

4032040320

m=4m = 4

00

00

00

00

00

00

1008010080

3024030240

m=5m = 5

00

00

00

00

00

14401440

1728017280

2160021600

m=6m = 6

00

00

00

00

480480

86408640

2160021600

96009600

m=7m = 7

00

00

00

9696

34563456

1641616416

1689616896

34563456

m=8m = 8

00

00

4848

21602160

1296012960

1824018240

64806480

432432

m=9m = 9

00

1616

11521152

96489648

1868818688

96489648

11521152

1616

在第一个测试用例中,所有 (m,k)(m, k) 对应的答案如下表所示:

k=0k = 0

k=1k = 1

k=2k = 2

m=3m = 3

00

00

66

m=4m = 4

00

44

22

  • (m,k)=(3,2)(m, k) = (3, 2) 的答案为 66,因为对每个长度为 33 的排列,恰好有 22 个下标 ii 满足 ai+ai+1≥3a_i + a_{i+1} \geq 3。
  • (m,k)=(4,2)(m, k) = (4, 2) 的答案为 22。事实上,恰好存在 22 个长度为 33 的排列,使得 ai+ai+1≥4a_i + a_{i+1} \geq 4 恰好成立 22 次:[1,3,2][1, 3, 2]、[2,3,1][2, 3, 1]。

因此,需输出的值为 29⋅0+210⋅0+211⋅6+212⋅0+213⋅4+214⋅2≡77 8240(mod01 000 000 007)2^9 \cdot 0 + 2^{10} \cdot 0 + 2^{11} \cdot 6 + 2^{12} \cdot 0 + 2^{13} \cdot 4 + 2^{14} \cdot 2 \equiv 77\,824 \phantom{0} (\text{mod} \phantom{0} 1\,000\,000\,007)。

在第二个测试用例中,所有 (m,k)(m, k) 对应的答案如下表所示:

k=0k = 0

k=1k = 1

k=2k = 2

k=3k = 3

m=3m = 3

00

00

00

2424

m=4m = 4

00

00

1212

1212

m=5m = 5

00

44

1616

44

  • (m,k)=(5,1)(m, k) = (5, 1) 的答案为 44。事实上,恰好存在 44 个长度为 44 的排列,使得 ai+ai+1≥5a_i + a_{i+1} \geq 5 恰好成立 11 次:[2,1,3,4][2, 1, 3, 4]、[3,1,2,4][3, 1, 2, 4]、[4,2,1,3][4, 2, 1, 3]、[4,3,1,2][4, 3, 1, 2]。

在第三个测试用例中,所有 (m,k)(m, k) 对应的答案如下表所示:

k=0k = 0

k=1k = 1

k=2k = 2

k=3k = 3

k=4k = 4

k=5k = 5

k=6k = 6

k=7k = 7

m=3m = 3

00

00

00

00

00

00

00

4032040320

m=4m = 4

00

00

00

00

00

00

1008010080

3024030240

m=5m = 5

00

00

00

00

00

14401440

1728017280

2160021600

m=6m = 6

00

00

00

00

480480

86408640

2160021600

96009600

m=7m = 7

00

00

00

9696

34563456

1641616416

1689616896

34563456

m=8m = 8

00

00

4848

21602160

1296012960

1824018240

64806480

432432

m=9m = 9

00

1616

11521152

96489648

1868818688

96489648

11521152

1616

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

首页