QOJ.ac

QOJ

時間限制: 1.0 s 記憶體限制: 512 MB 總分: 100 可 Hack ✓

#7328. 洗牌

统计

Yuuka 有一副 $n$ 张牌,牌上的数字分别为 $0, 1, 2, \dots, (n - 1)$。

初始时,牌从上到下的顺序为 $p_1, p_2, \dots, p_n$。在每一轮中,如果最顶端的牌上的数字为 $x$,Yuuka 会将这张牌向下移动 $x$ 个位置,使其成为牌堆中从上往下数的第 $(x + 1)$ 张牌。其他牌的相对顺序保持不变。

请问经过多少轮后,数字为 $0$ 的牌会到达最顶端?

输入格式

第一行包含一个整数 $n$ ($1 \le n \le 32$)。

第二行包含 $n$ 个不同的整数 $p_1, p_2, \dots, p_n$ ($0 \le p_i < n$)。

输出格式

输出一个整数,表示所需的轮数。如果数字为 $0$ 的牌永远无法到达最顶端,则输出 “-1”。

样例

输入 1

5
1 3 2 4 0

输出 1

13

输入 2

2
0 1

输出 2

0

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.