問題一覧 > 通常問題

No.3075 Mex Recurrence Formula

レベル : / AI推定難易度 : 1500 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 70
作問者 : 👑 binap / テスター : Iroha_3856 👑 hamamu 👑 qand
お気に入りにしたユーザー ProblemId : 12092 / 自分の提出
問題文最終更新日: 2025-03-24 23:58:58
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
yukicoder contest 462 (順位表) の他の問題:

Problem Statement

There is a sequence of non-negative integers $A = (A_1, A_2, \cdots)$.

The terms $A_1$ through $A_N$ are given as input, and each term from the $N+1$-th onward is the ${\rm mex}$ of the immediately preceding $N$ terms. That is, the following formula holds for $i = N + 1, N + 2, \cdots$.

$$A_i = {\rm mex}(A_{i-N}, A_{i-N+1}, \cdots, A_{i - 1})$$

Find $A_X$.

What is $\rm mex$?

${\rm mex}(B_1, B_2, \cdots, B_M)$ denotes the smallest non-negative integer not contained in the set $\{B_1, B_2, \cdots, B_M\}$. For example, ${\rm mex}(2, 1, 0, 4) = 3, {\rm mex}(2, 2, 3) = 0$.

Constraints

  • $1\leq N \leq 2\times 10^5$

  • $1\leq X \leq 10^{18}$

  • $0\leq A_i \leq 10^9$ $(1\leq i \leq N)$

  • All inputs are integers.

Input

$N$ $X$
$A_1$ $A_2$ $\cdots$ $A_N$

Output

Print the value of $A_X$ on $1$ line.

Sample

Sample 1
Input
4 6
1 0 1 3
Output
4
  • $A_5 = {\rm mex}(A_1, A_2, A_3, A_4) = {\rm mex}(1, 0, 1, 3) = 2$

  • $A_6 = {\rm mex}(A_2, A_3, A_4, A_5) = {\rm mex}(0, 1, 3, 2) = 4$

The terms from $A_5$ onward are computed in the same way. Therefore, the sequence $A$ is $A = (1, 0, 1, 3, 2, 4, \cdots)$.

Sample 2
Input
5 2
3 1 4 1 5
Output
1
Sample 3
Input
8 51
7 5 2 6 0 3 3 7
Output
8

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