問題一覧 > 通常問題

No.616 Strange Sort

レベル : / AI推定難易度 : 1550 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 104
作問者 : tsutaj / テスター : はむこ
お気に入りにしたユーザー ProblemId : 2017 / 自分の提出
問題文最終更新日: 2026-06-26 05:05:22
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
Advent Calendar Contest 2017 (順位表) の他の問題:

Problem Statement

Ebi-chan is studying sorting. One day, she found a strange sort called "tsutaj sort". Apparently, it is used to quickly obtain a sequence that is roughly in ascending order.

When a sequence $a$ is tsutaj-sorted, it always returns a sequence $a'$ whose inversion number is at most $K$. Here, the inversion number is the number of pairs $(i, j)$ such that $i < j$ and $a_i' > a_j'$.

Ebi-chan is curious how many possible sequences there are after tsutaj sort. Find the total number of rearrangements of the given sequence whose inversion number is at most $K$, modulo $1,000,000,007$.

Input

$N$ $K$
$a_1$ $a_2$ $\dots$ $a_N$

The input is given in $2$ lines.

The $1$st line contains the length $N$ of the sequence and the upper bound $K$ on the inversion number of the sorted sequence.

The $2$nd line contains the sequence $a$. The $i$-th element is $a_i$.

Constraints

  • $1 \leq N \leq 300$
  • $0 \leq K \leq \frac{N(N-1)}{2}$
  • $1 \leq a_i \leq 10^9$
  • All $a_i$ are distinct. That is, if $i \neq j$ then $a_i \neq a_j$.

Output

Output in $1$ line the total number of rearrangements of the given sequence whose inversion number is at most $K$, modulo $1,000,000,007$.

Sample

Sample 1
Input
3 1
1 2 3
Output
3

There are $3$ sequences satisfying the condition.

  • 1 2 3 (inversion number $0$)
  • 1 3 2 (inversion number $1$)
  • 2 1 3 (inversion number $1$)
Sample 2
Input
5 7
1 4 5 8 2
Output
106
Sample 3
Input
13 78
3 1 4 15 9 2 6 5 35 89 7 93 23
Output
227020758

Note that you should output the remainder modulo $1,000,000,007$.

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。