公式

D - cresc. 解説 by evima


Given \(S\), once \(A_1\) is determined, the values \(A_2, \ldots, A_{N+1}\) are determined. Consider associating each \(S\) with the \(A\) that has the smallest \(A_1\) satisfying the condition.

The set of valid sequences \(S\) is in one-to-one correspondence with the following set of sequences \(A\).

  • The subsequence \(A_{odd}\) consisting of odd-indexed elements of \(A\) is non-decreasing.
  • The subsequence \(A_{even}\) consisting of even-indexed elements of \(A\) is non-decreasing.
  • Either the first element of \(A_{odd}\) is \(0\), or the last element of \(A_{even}\) is \(M\).

The size of this set of sequences \(A\) can be expressed using binomial coefficients.

The time complexity is \(O(N + M)\).

投稿日時:
最終更新: