QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 1024 MB Total points: 100

#8351. Ruin the legend

الإحصائيات

题目描述

给一个正整数序列 $a_1,a_2,...,a_n(a_1 < a_2 < ... < a_n)$,求有多少种这个序列的排列 $\{p_n\}$ 满足对所有 $1\leq i\leq n-1$,有 $|p_i-p_{i+1}|\neq k$,答案模 $998244353$。

输入格式

第一行两个正整数 $n,k$,分别代表序列中的元素个数和限制中 $k$ 的值。

第二行 $n$ 个正整数 $a_1,a_2,...,a_n$。

输出格式

一行一个正整数,代表满足要求的排列个数。

样例输入 1

4 1
1 2 3 4

样例输出 1

2

样例解释 1

只有 $3,1,4,2$ 和 $2,4,1,3$ 两种排列满足条件。

样例输入 2

7 2
1 2 3 4 6 7 8

样例输出2

1272

数据范围

保证 $n\leq 5\times 10^3,k\leq 10^6,a_i\leq 10^9$ 。

subtask1(20pts):保证 $n\leq 10$ 。

subtask2(30pts):保证 $n\leq 400$ 。

subtask3(20pts):保证 $n\leq 1000$ 。

subtask4(30pts):无特殊限制

About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.