QOJ.ac

QOJ

Límite de tiempo: 1 s Límite de memoria: 1024 MB Puntuación total: 100

#16803. Breakout

Estadísticas

糟糕!在你给梅林(Merlin)的一个谜题打了低分后,他为了报复,把你关进了他的魔法地牢!这个地牢可以建模为一个圆,其中有 $n$ 个房间沿圆周排列。房间按顺时针方向从 $1$ 到 $n$ 进行编号。

你从房间 $1$ 出发,并且知道其中一个房间里有出口。为了到达出口房间,你可以沿顺时针或逆时针方向走到相邻的房间。然而,梅林非常聪明。为了阻碍你逃脱,他在连接两个相邻房间的几条走廊中放置了木箱。要通过一条走廊,你必须破坏阻挡它的所有木箱。

你希望尽快到达出口房间。为了逃脱,你最少需要破坏多少个木箱?

图 F.1:样例情况的示意图。

输入格式

输入的第一行包含三个整数 $n$、$x$ 和 $m$($2 \le n \le 1\,000$,$1 \le x \le n$,$0 \le m \le 1\,000$),表示有 $n$ 个房间,其中房间 $x$ 是出口房间,并且有 $m$ 个木箱。

接下来的 $m$ 行,每行包含一个整数 $r$($1 \le r \le n$),表示在房间 $r$ 与沿圆周顺时针方向的下一个房间之间的走廊中有一个木箱。如果 $r = n$,则表示该木箱位于房间 $n$ 与房间 $1$ 之间的走廊中。这些整数可能包含重复值,这意味着同一条走廊中可能会放置多个木箱。

输出格式

输出一个整数,表示你为了逃脱最少必须破坏的木箱数量。

样例

输入样例 1

8 4 5
2
6
3
2
8

输出样例 1

2

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.